【发布时间】:2018-03-10 09:15:45
【问题描述】:
使用 Google Maps iOS SDK,如果长按特定标记,我希望能够打印 GMSMarker 的坐标。
我首先从字典中获取所有坐标,然后在地图上为所有坐标放置标记:
func placeMapMarkers() {
for item in self.finalDictionary as [Dictionary<String, String>] {
let lat = item["lat"] as! String
let lon = item["lon"] as! String
let SpotLat = Double(lat)
let SpotLon = Double(lon)
let SpotLocation = CLLocationCoordinate2DMake(SpotLat!, SpotLon!)
DispatchQueue.main.async(execute: {
self.SpotMarker = GMSMarker(position: SpotLocation)
self.SpotMarker?.icon = self.imageWithImage(image: UIImage(named: "SpotIcon")!, scaledToSize: CGSize(width: 35.0, height: 35.0))
self.SpotMarker?.title = "Long press to navigate here"
self.SpotMarker?.map = self.mapView
})
longPress(mapView: self.mapView, didLongPressAtCoordinate: SpotLocation)
}
}
我的 longPress 函数调用在上面的 placeMapMarkers 函数本身中,因为我想在放置标记时识别是否长按了特定标记(我的想法可能有误)。
我的长按功能如下。
//This is long Press function:-
func longPressView(mapView: GMSMapView!, didLongPressAtCoordinate coordinate: CLLocationCoordinate2D) {
//Here handle your long press on map marker like:-
print("long pressed at \(coordinate)")
}
问题是我正在“长按”坐标字典中的所有坐标。
我想要
- 在字典中为所有坐标放置标记
- 长按特定标记
- 并仅打印长按的特定标记的坐标。
我该怎么做?看了其他解决方案,没能解决多少。
【问题讨论】:
标签: ios google-maps swift3 long-press uilongpressgesturerecogni