Чтобы добавить аннотации к MapKit , необходимо реализовать делегат аннотаций, который реализует протокол MKAnnotation . Когда вы добавляете аннотацию к карте, вы создаете экземпляр своего объекта Annotation Delegate, а затем добавляете его в MKMapView . MKAnnotation включает в себя position свойство, которое вы можете запросить, чтобы определить местоположение аннотации:
@interface AnnotationDelegate : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@end
Чтобы добавить аннотацию на карту:
AnnotationDelegate * annotationDelegate = [[[AnnotationDelegate alloc] init] autorelease];
[mapView addAnnotation:annotationDelegate];
Затем, когда вы получите calloutAccessoryControlTapped callback, вы можете привести MKAnnotationView .annotation к вашему классу делегата Annotation и затем запросить position свойство:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
AnnotationDelegate * delegate = (AnnotationDelegate*)view.annotation;
// do stuff with delegate.position;
}