Mapkit在查找注释当前位置时的问题

时间:2010-03-08 22:19:53

标签: iphone mapkit

我正在我的应用程序中实现地图工具包,我第一次使用它,所以请告诉我如何找到注释的当前位置。?

1 个答案:

答案 0 :(得分:2)

要向 MapKit 添加注释,您需要实现一个实现 MKAnnotation 协议的注释代理。将注释添加到地图时,您将创建Annotation Delegate对象的实例,然后将其添加到 MKMapView MKAnnotation 包含位置属性,您可以查询该属性以确定注释的位置:

@interface AnnotationDelegate : NSObject <MKAnnotation> {
    CLLocationCoordinate2D coordinate;
}

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

@end

要将注释添加到地图中:

AnnotationDelegate * annotationDelegate = [[[AnnotationDelegate alloc] init] autorelease];
[mapView addAnnotation:annotationDelegate];

然后,当您获得 calloutAccessoryControlTapped 回调时,可以将 MKAnnotationView .annotation强制转换为Annotation Delegate类,然后查询 position 属性:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    AnnotationDelegate * delegate = (AnnotationDelegate*)view.annotation;
    // do stuff with delegate.position;
}