I would like to remove all annotations from my mapview without the blue dot of my position. When I call:
[mapView removeAnnotations:mapView.annotations];
all annotations are removed.
In which way can I check (like a for loop on all the annotations) if the annotation is not the blue dot annotation?
EDIT (I've solved with this):
for (int i =0; i < [mapView.annotations count]; i++) {
if ([[mapView.annotations objectAtIndex:i] isKindOfClass:[MyAnnotationClass class]]) {
[mapView removeAnnotation:[mapView.annotations objectAtIndex:i]];
}
}
For Swift 3.0
i modified like this
Isn't it easier to just do the following:
it easier to just do the following:
shortest way to clean all annotations and preserving MKUserLocation class annotation
If you like quick and simple, there's a way to filter an array of the MKUserLocation annotation. You can pass this into MKMapView's removeAnnotations: function.
I assume this is pretty much the same as the manual filters posted above, except using a predicate to do the dirty work.