当用户触摸屏在谷歌地图迅速下降一针

P.T*_*.Tb 3 google-maps google-maps-markers ios swift

我想Marker在Google地图中添加和删​​除(固定)。

我想长时间触摸掉别针并将其删除。我想用它来选择我的目的地。我该怎么做?

let  position = CLLocationCoordinate2DMake(10, 10)
let marker = GMSMarker(position: position)
marker.map = mapView
Run Code Online (Sandbox Code Playgroud)

Sat*_*ync 5

对于那些正在寻找使用Swift的完整代码段的人:

  1. 实施协议 GMSMapViewDelegate
  2. 拖动GMSMapView的实例 @IBOutlet weak var googleMapView: GMSMapView!
  3. 提起通过GMSMapView代表内viewDidLoad()googleMapView.delegate = self
  4. 实现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 }