在 Swift 中检测 GMSPolyline 上的点击?
Detect tap on GMSPolyline in Swift?
我正在努力检测在我的 Google 地图上绘制的 GMSPolyline 上的点击,它适用于 GMSpolygones,但同样的方法似乎不适用于折线。我目前适用于多边形的方法是:
if (GMSGeometryContainsLocation(coordinate, polygon.path!, false)) {
...
}
有什么关于如何检测折线上的点击的建议吗?还是接近?
根据他们的 API documentation,GMSPolyline
继承自 GMSOverlay
这意味着 GMSPolyline
具有 属性 tappable
.所以你想要这样的东西
let polyLine: GMSPolyline = GMSPolyline(path: newPath)
polyLine.isTappable = true
polyline.zIndex = 0
polyline.map = yourGoogleMap
那么你的 GMSMapViewDelegate
应该会通知你在 GMSPolyline
层内的任何地方使用此功能点击
func mapView(_ mapView: GMSMapView, didTap overlay: GMSOverlay)
{
print(overlay.zindex)
print("User Tapped Layer: \(overlay)")
}
您可以使用 isTappable
属性 的 GMSPolyline。
isTappable
If this overlay should cause tap notifications.
polyline.isTappable = true
GMSPolyline
继承自 GMSOverlay
。因此,为了检测点击覆盖 GMSMapViewDelegate
提供了一个委托方法:
- mapView:didTapOverlay: Called after an overlay has been tapped.
只要点击折线,就会调用 GMSMapViewDelegate
方法 didTapOverlay
func mapView(_ mapView: GMSMapView, didTap overlay: GMSOverlay) {
//Write your code here
}
此外,此方法可用于 GMSPolygon
,因为它也继承自 GMSOverlay
。
我正在努力检测在我的 Google 地图上绘制的 GMSPolyline 上的点击,它适用于 GMSpolygones,但同样的方法似乎不适用于折线。我目前适用于多边形的方法是:
if (GMSGeometryContainsLocation(coordinate, polygon.path!, false)) {
...
}
有什么关于如何检测折线上的点击的建议吗?还是接近?
根据他们的 API documentation,GMSPolyline
继承自 GMSOverlay
这意味着 GMSPolyline
具有 属性 tappable
.所以你想要这样的东西
let polyLine: GMSPolyline = GMSPolyline(path: newPath)
polyLine.isTappable = true
polyline.zIndex = 0
polyline.map = yourGoogleMap
那么你的 GMSMapViewDelegate
应该会通知你在 GMSPolyline
层内的任何地方使用此功能点击
func mapView(_ mapView: GMSMapView, didTap overlay: GMSOverlay)
{
print(overlay.zindex)
print("User Tapped Layer: \(overlay)")
}
您可以使用 isTappable
属性 的 GMSPolyline。
isTappable
If this overlay should cause tap notifications.
polyline.isTappable = true
GMSPolyline
继承自 GMSOverlay
。因此,为了检测点击覆盖 GMSMapViewDelegate
提供了一个委托方法:
- mapView:didTapOverlay: Called after an overlay has been tapped.
只要点击折线,就会调用 GMSMapViewDelegate
方法 didTapOverlay
func mapView(_ mapView: GMSMapView, didTap overlay: GMSOverlay) {
//Write your code here
}
此外,此方法可用于 GMSPolygon
,因为它也继承自 GMSOverlay
。