Working With Annotation
suggest changeGet All Annotations
These snippets assume an MKMapView named mapView. Removing every annotation also removes the user-location annotation when showsUserLocation is on.
// the following returns all annotation objects added on the map
NSArray *allAnnotations = mapView.annotations;
Get Annotation View
for (id<MKAnnotation> annotation in mapView.annotations)
{
MKAnnotationView* annotationView = [mapView viewForAnnotation:annotation];
if (annotationView)
{
// Do something with annotation view
// for example, change the image of the annotation view
annotationView.image = [UIImage imageNamed:@"SelectedPin.png"];
}
}
Remove All Annotations
[mapView removeAnnotations:mapView.annotations];
Remove Single Annotation
//getting all Annotation
NSArray *allAnnotations = mapView.annotations;
if (allAnnotations.count > 0)
{
//getting first annotation
id <MKAnnotation> annotation=[allAnnotations firstObject];
//removing annotation
[mapView removeAnnotation:annotation];
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents