John John - 1 month ago 17
iOS Question

Get Latitude and Longitude from Annotation view

How do I get the latitude and longitude of an annotationView placed on my mapView? I need to get it when the rightAccessory gets tapped.

The

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
method does return the MKAnnotationView which has a
coordinate
property to be used. But I want the lat and long. How do I convert the coordinate to lat and long?

Thanks.

Answer

coordinate is a CLLocationCoordinate2D, which is a struct containing latitude and longitude.

coordinate is actually a property of MKAnnotation. MKAnnotationView has an MKAnnotation property named annotation.

So, in the method you mentioned you should be able to get to the latitude using [[view annotation] coordinate].latitude and longitude using [[view annotation] coordinate]. longitude.

Comments