I use removeAnnotations
to remove my annotations from mapView
but same it remove user location ann. How can I prevent this, or how to get user ann
To clear all the annotations from the map:
[self.mapView removeAnnotations:[self.mapView annotations]];
To remove specified annotations from Mapview
for (id <MKAnnotation> annotation in self.mapView.annotations)
{
if (![annotation isKindOfClass:[MKUserLocation class]])
{
[self.mapView removeAnnotation:annotation];
}
}
Hope this may help you.
How about some NSPredicate
filter?
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"className != %@", NSStringFromClass(MKUserLocation.class)];
NSArray *nonUserAnnotations = [self.mapView.annotations filteredArrayUsingPredicate:predicate];
[self.mapView removeAnnotations:nonUserAnnotations];
Life is always better with NSPredicate filter