Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect tap on GMSPolyline in Swift?

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?

like image 684
Recusiwe Avatar asked Nov 22 '16 18:11

Recusiwe


1 Answers

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)")
}
like image 122
eshirima Avatar answered Oct 22 '22 12:10

eshirima