Correct order display of UIAnnotationView

I can't find a way to correctly and reliably order two annotation view on the MapKit map.


i tryed to change zindex, some other strange hacks I forgot, but never found a reliable way to achieve this.


As an example, please see the eclosed screen capture of our app: the arrow should display under the harbor annotation.

https://ibb.co/qWxMcS4


Is there a solution?

In which order do you create the arrow wrt the labels ?

I tried every orders

Currently, for each map pan, I remove all annotations which become out of the screen, add all annotation that enter the screen, and keep unchanged the annotations which stays.


But for testing purpose I also tried a simpler implementation : by removing all annotations every time, and 1) adding first the arrows, then the labels, or 2) first the labels and then the arrows, the result is exacly the same : arrows are always above the labels.


I suppose this is MapKit OpenGL optimisations, and my arrows (polylines rendered with UIBezierPath) would be rendered before my harbors (UIImage + UILabel)

Hi, thanks for your answer.


Your suggestion about using overlay is very interesting. I haven't tried yet, but i'm afraid that overlay element size depends of the map zoom level. I'll check that.


Your other links are all about bringing to front or sending to back the MKAnnotationViews from their unique superview, like


annotationView.superview?.bringSubviewToFront(annotationView)


Maybe it worked in 2009 (these are pretty old links), but il does not work anymore. It think mapkit is doing its secret sauce in rendering annotation views.


I would love hear some Apple developers on this point.

Year 2021 and this is still mystery. On iOS 14 there is zPriority on annotation view, but what if I want to be backward compatible with older os?

Correct order display of UIAnnotationView
 
 
Q