问题
I am implementing map kit in my app and i am using this first time so please tell me how to find the current position of the annotation.?
回答1:
To add annotations to MapKit you need to implement an Annotation Delegate which implements the MKAnnotation protocol. When you add the annotation to the map you create an instance of you Annotation Delegate object and then add it to the MKMapView. MKAnnotation includes a position property which you can query to determine the location of the annotation:
@interface AnnotationDelegate : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@end
To add your annotation to the map:
AnnotationDelegate * annotationDelegate = [[[AnnotationDelegate alloc] init] autorelease];
[mapView addAnnotation:annotationDelegate];
Then when you get a calloutAccessoryControlTapped callback, you can cast the MKAnnotationView.annotation to your Annotation Delegate class and then query the position property:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
AnnotationDelegate * delegate = (AnnotationDelegate*)view.annotation;
// do stuff with delegate.position;
}
来源:https://stackoverflow.com/questions/2405233/mapkit-issue-in-finding-annotation-current-position