Is there a simple way to delete all the annotations on a map without iterating through all the displayed annotations in Objective-c?
+2
A:
Yes, here is how
[mapView removeAnnotations:mapView.annotations]
Hussain Saleem
2010-06-12 06:39:21
does this remove the user location too? what if I want to remove all the annotations besides the user location?
kevin Mendoza
2010-06-13 22:17:29
yes, it will remove the user location as well.to avoid removing the user location marker, make a copy of the annotations array, filter out the user location marker.Here is how you can identify the user location markerif ( [annotation isKindOfClass:[ MKUserLocation class]] ) // user location marker or if (annotation == userLocation ) // user location marker
Hussain Saleem
2010-06-21 04:23:15
+2
A:
Here's how to remove all annotations except the user location, written out explicitly because I imagine I will come looking for this answer again:
NSMutableArray *locs = [[NSMutableArray alloc] init];
for (id <MKAnnotation> annot in [mapView annotations])
{
if ( [annot isKindOfClass:[ MKUserLocation class]] ) {
}
else {
[locs addObject:annot];
}
}
[mapView removeAnnotations:locs];
[locs release];
locs = nil;
vvanhee
2010-08-29 07:02:00