Mapkit issue in finding annotation current position

霸气de小男生 提交于 2019-12-23 17:08:39

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!