当用户点击的覆盖,下面的代码被触发:获取LAT和LONG
func mapView(_ mapView: GMSMapView, didTap overlay: GMSOverlay) {
}
我怀疑我们是否可以提取具有覆盖的精确的纬度和经度坐标被挖掘?
谢谢!
当用户点击的覆盖,下面的代码被触发:获取LAT和LONG
func mapView(_ mapView: GMSMapView, didTap overlay: GMSOverlay) {
}
我怀疑我们是否可以提取具有覆盖的精确的纬度和经度坐标被挖掘?
谢谢!
如果您只是希望获得精确的坐标,无论您是否在Overlay上进行挖掘,那么还有另一个GMSMapViewDelegate
的代理,每当我们点击GoogleMaps
时都会调用该代理。在这个代表中,您可以获得您在地图上点击的确切坐标,而无需在叠加层上进行点击。
雨燕3.0
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
print(coordinate.latitude)
print(coordinate.longitude)
}
如果你想只在敲击标记坐标,然后用这个委托方法
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
print(marker.position.latitude)
print(marker.position.longitude)
return true
}
确保让您的叠加层不可点击
overlay.isTappable = false
更多信息参见here
我在地图上绘制了一条多段线,我需要把它打开。所以我需要'overlay.isTappable = true'。 –
@JaysonTamayo我想''GoogleMapsSDK'中没有方法可以给你攻丝叠加的确切坐标。你只能接收到一个你点击一个叠加层的事件,但不会在点击叠加层时获得坐标,因为'GMSOverlay'类没有坐标选项。 –
应该有另一种方式。有没有可能有'didTapAt'同时也听重叠点击? –
为了解决这个问题,我们需要的2种方法一起, 所以我的方式,我希望它会在这个问题上帮助它们结合在一起:
func mapView(_ mapView: GMSMapView, didTap overlay: GMSOverlay) {
print(overlay)
}
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
print(coordinate)
for polyline in polylines {
if GMSGeometryIsLocationOnPath(coordinate, polyline.path!, true) {
self.mapView(mapView, didTap: polyline)
}
}
for polygon in polygons {
if GMSGeometryContainsLocation(coordinate, polygon.path!, true) {
self.mapView(mapView, didTap: polygon)
}
}
}
如果用户点击了coordinate
我们会解决这个问题,然后检查,如果这coordinate
包含在任何Polyline
或Polygon
我们之前已经确定,所以我们fire
为overlay
事件didTap overlay
。
确保创建polylines
和polygons
isTappable = false
而但考虑到这一事件会为每overlay
窃听即使如果他们是overlaped
,你可以把return
当if
成功拿被解雇第一个overlay
只有
查看我的回答 –