So you can't get the didTapAtCoordinateMethod to fire for an overlay tap. However I did find a slightly dirty workaround.
Using an overlay to draw polylines, we need a way to recognize where a polyline was tapped. So when drawing polylines we can build them like this.
//draw line
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
polyline.strokeColor = [UIColor purpleColor];
polyline.tappable = TRUE;
polyline.map = self.googleMapView;
polyline.title = routestring;
Where routestring is a built string from
routestring = [NSString stringWithFormat:@"%@/%@/%@",lat,lng,[annnotationobject objectForKey:@"linkId"]];
And lat and lng are string values of our coordinates. The last part is an ID for the polyline.
The routestring is storing the coordinates and an ID separated by '/' so that we can use component path of string to look them up later. This is assigned to the polylines title.
Now when the overlay is tapped:
-(void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlay{
NSString *path = overlay.title;
//Finding componentpaths of string
NSArray *pathparts = [path pathComponents];
NSString *lat = [pathparts objectAtIndex:0];
NSString *lng = [pathparts objectAtIndex:1];
NSString *linkID = [pathparts objectAtIndex:2];
//Here we are building a marker to place near the users tap location on the polyline.
GMSMarker *marker = [GMSMarker markerWithPosition:CLLocationCoordinate2DMake([lat doubleValue],[lng doubleValue])];
marker.title = overlay.title;
marker.snippet = @"ROUTE DATA";
marker.map = self.googleMapView;
//This will popup a marker window
[self.googleMapView setSelectedMarker:marker];
}
We can use component paths of the string we built(separated by "/")to get the latitude and longitude coordinates from the polyline. Then assign them a marker to popup information on the overlay item.
didTapAtCoordinate
for overlays – Unshaped