John John - 1 year ago 150
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.


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


Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download