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.zIndex = 0
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(overlay.zindex)
print("User Tapped Layer: \(overlay)")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With