我想在Google地圖中添加和刪除Marker
(pin)。當谷歌地圖swift用戶觸摸屏時放下一個PIN
我想長時間放下引腳並將其刪除。我想用它來選擇我的目的地。我該怎麼做?
let position = CLLocationCoordinate2DMake(10, 10)
let marker = GMSMarker(position: position)
marker.map = mapView
我想在Google地圖中添加和刪除Marker
(pin)。當谷歌地圖swift用戶觸摸屏時放下一個PIN
我想長時間放下引腳並將其刪除。我想用它來選擇我的目的地。我該怎麼做?
let position = CLLocationCoordinate2DMake(10, 10)
let marker = GMSMarker(position: position)
marker.map = mapView
此代碼應該對您有所幫助!
//MARK: GMSMapViewDelegate Implimentation.
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D)
{
plotMarker(AtCoordinate: CLLocationCoordinate2D.init(latitude: 17.432699, longitude: 78.374674),onMapView: mapView)
}
//MARK: Plot Marker Helper
private func plotMarker(AtCoordinate coordinate : CLLocationCoordinate2D, onMapView vwMap : GMSMapView) -> Void
{
let marker = GMSMarker(position: coordinate)
marker.map = vwMap
}
希望有幫助!
對於誰正在尋找使用斯威夫特一個完整的代碼片段的那些:
GMSMapViewDelegate
@IBOutlet weak var googleMapView: GMSMapView!
的實例viewDidLoad()
GMSMapView中提到作爲代表googleMapView.delegate = self
didTapAt
委託功能:func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D){ print("You tapped at \(coordinate.latitude), \(coordinate.longitude)") googleMapView.clear() // clearing Pin before adding new let marker = GMSMarker(position: coordinate) marker.map = googleMapView }