I'm working on a map with more than 5000 pins. Everytime I change the region I add or remove annotationViews based on how much zoom there is.
The only problem is this (extreme test):
When there is little more space between the pins the callout moves ontop, but often the red pins is ontop.
I'm only using basic MKPinAnnotationView. No custom callout.
I did try implementing the Z-ordering-category by Aaron Z-ordering of MKAnnotationViews but didn't seems to help.
EDIT:
I haven't solved it yet, but I do have some thoughts.
MapKit is poorly written. MapView has the responsibility to order views so at least the selected one stays on top.
Maybe it's too many annotations for mapView to handle.
HOW TO REPLICATE
just add 5000 annotations.
-(void)addAnnotations
{
NSMutableArray *annotations = [NSMutableArray array];
for(int i=0;i<5000;i++) {
CGFloat latDelta = rand()*0.125/RAND_MAX - 0.02;
CGFloat lonDelta = rand()*0.130/RAND_MAX - 0.08;
CGFloat lat = 59.189358;
CGFloat lng = 18.267839;
CLLocationCoordinate2D newCoord = {lat+latDelta, lng+lonDelta};
DTSAnnotation *annotation = [DTSAnnotation annotationWithCoord:newCoord];
[annotation setTitle:@"."];
[annotations addObject:annotation];
}
[[self mapView]addAnnotations:annotations];
}