I am currently looking for a way to make a route (MGPLPolyline) tappable such that a user can choose between two possible routes under Mapbox. Unfortunately the route annotation doesn't seem to be tappable at all:
While i have properly set my MGLMapViewDelegate
this method:
func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation)
is never invoked.
What did i miss knowing that each line inherited from MGLPolyline
which is a subclass of an MGLAnnotation
(which i was expected to be tappable...).
The Mapbox iOS API doesn't support that yet, unfortunately. See here.
There are a couple of workarounds within that link that you could try though.
UPDATE:
This is now possible: Check here.
You could do the following:
First, when you create the polyline do the following:
let polyline = CustomPolyline(coordinates: &coordinates, count: UInt(coordinates.count))
polyline.title = "" //It does not seem to matter what you set it to.
polyline.color = .darkGray
Then in the following method return false:
func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
// Always allow callouts to popup when annotations are tapped.
print("ran?")
return false
}