检测Swift中的GMSPolyline? [英] Detect tap on GMSPolyline in Swift?

查看:183
本文介绍了检测Swift中的GMSPolyline?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在检测在我的Google地图上绘制的GMSPolyline上的水龙头时遇到困难,它对GMSpolygones运行得很好,但同样的方法似乎不适用于多段线。我现在的方法适用于多边形,它是:
$ b $ pre $ if(GMSGeometryContainsLocation(coordinate,polygon.path!,false)){
...
}

如何检测多段线上的点击?或者只是靠近它?

解决方案

根据他们的API 继承从继承 / code>这意味着 GMSPolyline 具有 tappable 属性。所以你需要这样的东西



pre $ let polyLine:GMSPolyline = GMSPolyline(path:newPath)
polyLine.isTappable = true
polyline.map = yourGoogleMap

然后你的 GMSMapViewDelegate 应该使用此函数通知您在 GMSPolyline 图层中的任意位置。

  func mapView(_ mapView:GMSMapView,didTap overlay:GMSOverlay)
{
print(User Tapped Layer:\(overlay))
}


I'm struggling with detecting a tap on a GMSPolyline drawn on my Google map, it works just fine with GMSpolygones, but the same approach doesn't seem to work with polyline. My current approach, which works for polygones, is:

if (GMSGeometryContainsLocation(coordinate, polygon.path!, false)) {
    ...
}

Any suggestions how to detect taps on a polyline? Or just close to it?

解决方案

According to their API documentation, GMSPolyline inherits from GMSOverlay which means a GMSPolyline has the property tappable. So you'd want something like this

let polyLine: GMSPolyline = GMSPolyline(path: newPath)
polyLine.isTappable = true
polyline.map = yourGoogleMap

Then your GMSMapViewDelegate should notify you of the tap anywhere within the GMSPolyline layer with this function

func mapView(_ mapView: GMSMapView, didTap overlay: GMSOverlay)
{
  print("User Tapped Layer: \(overlay)")
}

这篇关于检测Swift中的GMSPolyline?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆