ios - 长按删除 Google map GMSMarker

标签 ios swift google-maps swift3 maps

我对使用 google map API 还很陌生。我试图为用户提供通过按住标记来从 map 上删除标记的选项。我知道谷歌地图有一个内置的markerTapped函数以及didLongPressOnInfoWindow,但我似乎找不到一种方法来检测标记本身的长按。

我想知道是否有人知道如何在标记本身上实现长按手势识别器?或者是否有比长按标记更直观的方法从 map 上删除标记?

提前致谢

最佳答案

删除标记

In 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

希望对您有很大帮助。

关于ios - 长按删除 Google map GMSMarker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45517545/

相关文章:

ios - 单例创建,在 ViewController 中使用时出错?

ios - 这是什么意思 Apple 实现已被弃用,但仍然可以使用它。不使用它的原因?

ios - 无法使用类型为 (String, Int) Swift 2 的索引为类型 [(String, Int)] 的值下标

Android Google Map如何检查gps位置是否在圆圈内

android - 上传谷歌室内地图? & 如何查看?

ios - 使用谷歌地图进行连续动画

IOS 8 无法从 UITextField 中关闭键盘

ios - 如何让我的 IOS 应用程序永远在后台播放音乐?

ios - 自动布局:使用 UIWebViews 自定义 UIView 高度约束

ios - 在 Swift 中将路径扩展名转换为小写