Annotation coordinates

Discussion in 'iOS Programming' started by Bloubul, Jul 9, 2011.

  1. Bloubul macrumors newbie

    Jul 9, 2011
    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. :)
  2. RonC macrumors regular

    Oct 18, 2007
    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):
    for (NSObject<MKAnnotation> *annot in map.annotations) {
    // do something with the annot MKAnnotation object regarding its coordinate, title, and subtitle
    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.
  3. Bloubul thread starter macrumors newbie

    Jul 9, 2011

    Thanks for the response. It was exactly what I was looking for.

Share This Page