Set MapKit annotation zIndex in declaration

Using SwiftUI, MapKit and the Map() view in iOS 17, I'm adding markers and annotations to the map instance. However it seems regardless of what order they are added, they are rendered with random Z-index values. I've not found any modifiers to specify any kind of priority.

Is there a way to declare Z-index priority of Marker and Annotation views?

Answered by matarali in 796958022

@DancesWithDingo From my experiments the z-index of annotations is determined by their latitude value. The lower the value, the higher the z-index. So, for example. This: CLLocationCoordinate2D(latitude: 37.66183, longitude: -122.37757 will overlap this: CLLocationCoordinate2D(latitude: 37.736555, longitude: -122.256918

its definitely random. trying many things right now. Will update if i have any sucess

Accepted Answer

@DancesWithDingo From my experiments the z-index of annotations is determined by their latitude value. The lower the value, the higher the z-index. So, for example. This: CLLocationCoordinate2D(latitude: 37.66183, longitude: -122.37757 will overlap this: CLLocationCoordinate2D(latitude: 37.736555, longitude: -122.256918

Set MapKit annotation zIndex in declaration
 
 
Q