我对使用 google map API 还很陌生。我试图为用户提供通过按住标记来从 map 上删除标记的选项。我知道谷歌地图有一个内置的markerTapped函数以及didLongPressOnInfoWindow,但我似乎找不到一种方法来检测标记本身的长按。
我想知道是否有人知道如何在标记本身上实现长按手势识别器?或者是否有比长按标记更直观的方法从 map 上删除标记?
提前致谢
最佳答案
删除标记strong>
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/