Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Bloubul

macrumors newbie
Original poster
Jul 9, 2011
6
0
I want to know if someone on this forum can assist me with a problem I have been having. I was wondering if it is possible to cycle through the annotations on a map using something like a 'for' statement and return annotation information such as coordiantes, subtitle etc.

Thanks in advance for anyone who takes the time to help. :)
 
Yes, you should be able to that. The attribute annotations on the MKMapView object provides an array of objects that respond to the MKAnnotation protocol. The coordinate attribute is a required element of MKAnnotation, while title and subtitle are optional.

You should be able to do something like (winging the code, sorry):
Code:
for (NSObject<MKAnnotation> *annot in map.annotations) {
// do something with the annot MKAnnotation object regarding its coordinate, title, and subtitle
    NSLog(@"Coordinate=(%0.3f,0.3f)",annot.coordinate.latitude,annot.coordinate.longitude);
}

The objects in the annotations array are likely a mixture of system (e.g., MKUserLocation) and your custom objects, you can test that annot object to see if it's one of yours (i.e., [annot isKindOfClass:[YourCustomClass class]]) and use more specific methods.
 
Thanks

Thanks for the response. It was exactly what I was looking for.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.