views:

290

answers:

2

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
does this remove the user location too? what if I want to remove all the annotations besides the user location?
kevin Mendoza
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
+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