Madan Mohan Madan Mohan - 1 year ago 86
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

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download