Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MapKit - iOS 13 - How to show pin annotations on top on the user location annotation?

Currently, when I try to add an annotation to the map in the user's location the annotation is not showing up. When I set the annotation (using the same code) besides the user's location it does show up.

The code:

let annotation = MKPointAnnotation()
annotation.coordinate = coordinate // set coordinate
annotation.title = "Title"
annotation.subtitle = "Subtitle"
mapView.addAnnotation(annotation)
like image 291
gabguy Avatar asked Sep 29 '19 12:09

gabguy


People also ask

What is MKMapView?

The MKMapView class supports the ability to annotate the map with custom information. Because a map may have large numbers of annotations, map views differentiate between the annotation objects used to manage the annotation data and the view objects for presenting that data on the map.


2 Answers

same issue here, it was working fine with iOS 12, now all annotations near the current location marker are not visible anymore. Critical information might be near the user location and needs to be displayed. This is mostly bad when you zoom out the map, as you don't know anymore if there is data since all annotations comes near the user location...

Is there a document that indicates this change from apple? I didn't find any... thanks in advance for someone that finds it.

If there is no options to turn off this behavior, the only workaround I can think of is to manually add the current location annotation ourselves...

like image 78
FooBrak Avatar answered Oct 14 '22 12:10

FooBrak


In the callback -mapView:viewForAnnotation on your MKMapViewDelegate be sure that the MKAnnotationView you return leaves its displayPriority as its default value which is MKFeatureDisplayPriorityRequired otherwise MapKit clusters your annotation view with the user location.

like image 36
Ilias Karim Avatar answered Oct 14 '22 12:10

Ilias Karim