Reputation: 13942
How to sort the annotations (MKAnnotation) on the MKMapView ?
Upvotes: 0
Views: 666
Reputation: 13942
For sorting annotations on MKMapView I use didAddAnnotationViews callback:
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
for (MKAnnotationView * annView in views) {
if ([annView.annotations isTop]) {
[[annView superview] bringSubviewToFront:annView];
} else {
[[annView superview] sendSubviewToBack:annView];
}
}
}
Upvotes: 0
Reputation: 11452
Try something like this,
NSArray *sortedArray = [mapView.annotations sortedArrayUsingComparator:<#^NSComparisonResult(id obj1, id obj2)cmptr#>];
Basically mapView.annotations will give you an access to your all annotations in NSArray, and then use sortedArray...methods (there are lots of different one
), which will help sorting your annotation array and return new sorted NSArry.
Hope this is what you are asking,
Cheers
Upvotes: 1