Madan Mohan Madan Mohan - 9 months ago 45
Objective-C Question

Can we get all the annotation views from MKMapView

Is there any direct method or any suggestion on how to get all the annotations from the MKMapView?

Thnak you,
Madan Mohan


You can access map's annotations using its annotations property. Getting views for all annotations may not be always possible as annotations that are not currently visible on the map may have no views associated with them, but for arbitrary annotation you can try to get a view using -viewForAnnotation: method.

So here how you can iterate through all map's annotations and try to access their views:

for (id<MKAnnotation> annotation in mapView.annotations){
    MKAnnotationView* anView = [mapView viewForAnnotation: annotation];
    if (anView){
       // Process annotation view