Mapkit 查找注释当前位置时出现问题

发布于 2024-08-24 07:33:20 字数 54 浏览 2 评论 0原文

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

無心 2024-08-31 07:33:20

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

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

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

@end

将注释添加到地图中:

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

然后,当您获得 calloutAccessoryControlTapped 时em> 回调,您可以将 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;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文