我想在 Google map 中添加和删除 Marker
(pin)。
我想通过长按放下图钉并将其移除。我想用它来选择我的目的地。我该怎么做?
let position = CLLocationCoordinate2DMake(10, 10)
let marker = GMSMarker(position: position)
marker.map = mapView
最佳答案
对于正在寻找使用 Swift 的完整代码片段的人:
- 实现协议(protocol)
GMSMapViewDelegate
- 拖动 GMSMapView 的一个实例
@IBOutlet weak var googleMapView: GMSMapView!
- 在
viewDidLoad()
中提及 GMSMapView Delegate 作为googleMapView.delegate = self
- 实现
didTapAt
委托(delegate)函数:
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D){
print("你点击了\(coordinate.latitude),\(coordinate.longitude)")
googleMapView.clear()//在添加新 Pin 之前清除 Pin
让标记= GMSMarker(位置:坐标)
marker.map = googleMapView
}
关于ios - 当用户在 google maps swift 中触摸屏幕时放下别针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37680199/