Annotation coordinates

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

  1. Bloubul macrumors newbie

    Joined:
    Jul 9, 2011
    #1
    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

    Joined:
    Oct 18, 2007
    Location:
    Chicago-area
    #2
    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.
     
  3. Bloubul thread starter macrumors newbie

    Joined:
    Jul 9, 2011
    #3
    Thanks

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

Share This Page