Mapkit在查找注释当前位置时出现问题 [英] Mapkit issue in finding annotation current position

查看:74
本文介绍了Mapkit在查找注释当前位置时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的应用程序中实现地图工具,这是我第一次使用,所以请告诉我如何查找注释的当前位置.

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.?

推荐答案

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

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

要将注释添加到地图:

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

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

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;
}

这篇关于Mapkit在查找注释当前位置时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆