开发者

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开发者_C百科 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.


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.


Add MKMapViewDelegate.

 func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView){      

let currentAnnotationLattitude = view.annotation?.coordinate.latitude

let currentAnnotationLongitude = view.view.annotation?.coordinate.longitude
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜