-1

I'd like to know if there is a way to best detect a users tap on a label? The new iOS15 Maps app allows a tap on e.g. a cities name and then shows informations about that city. I am now wondering if something similar can be done with mapbox?

I know that there is a mapView.visibleFeatures(in: myRect) function that can somehow help here. So I can convert my finger location to a rect and then get all features there. BUT... my city e.g. might have a label that is let's say 200 px wide. So I would need to have a quite large rect to find the point of my city label. And then I will also get all kinds of other labels that might be there. Maybe even not visible, but in the dataset.

Is there no way to ask the map what the frontmost element was when I tapped? So that when I tap on the far end of the label, I still get that ONE feature?

I am still using Mapbox V6.3... the latest before their last major update. But if it's not possible with that version, an answer about the latest V10.something would also be great.

Georg
  • 3,664
  • 3
  • 34
  • 75

1 Answers1

1

For v10, this example demonstrates how to identify features near a click. While the overall example is to a different end, the onMapClick functions shows the method to find a feature and then build an annotation.

https://docs.mapbox.com/ios/maps/examples/view-annotation-marker/