长按删除谷歌地图GMSMarker

时间:2017-08-05 02:04:03

标签: ios swift google-maps swift3 maps

我很高兴使用谷歌地图API。我试图通过按住标记让用户选择从地图中删除标记。我知道google maps有一个用于markerTapped和didLongPressOnInfoWindow的内置函数,但我似乎无法找到一种方法来检测标记本身的长按。

我想知道是否有人知道如何在标记本身上实现长按手势识别器?或者,如果可能有更直观的方法从地图中删除标记而不是长按标记?

提前致谢

1 个答案:

答案 0 :(得分:0)

删除标记

  

在Swift 3中

//Press on Button Forcefully for long time
let pressHold = UILongPressGestureRecognizer(target: self, action: #selector(pressHolding(sender:))
self.mapView.addGestureRecognizer(pressHold)

//Handle in pressHolding Function
func pressHolding(recognizer: UILongPressGestureRecognizer)
{
    if (recognizer.state == UIGestureRecognizerState.Began)
    {
        //Here you can do your task like delete or edit on market etc:-
    }
}

//This is long Press function:-
func mapView(mapView: GMSMapView!, didLongPressAtCoordinate coordinate: CLLocationCoordinate2D) {
   //Here handle your long press on map marker like:-
   let camera = GMSCameraPosition.camera(withLatitude: -33.8683, longitude: 151.2086, zoom: 6)
   let mapView = GMSMapView.map(withFrame: .zero, camera: camera)
   mapView.clear()
}

Here you can find Objective-C and Swift All available Function of Markers

希望它会对你有所帮助。