如何在 MKPinAnnotation 中存储与引脚相关的信息

发布于 2024-11-06 16:55:29 字数 756 浏览 5 评论 0原文

实际上,我已经从网络服务中检索了很多有关服务站的信息,它们在这里,我为每个站显示了一个引脚注释,以使用 UIButtonTypeDetailDisclosure 将其显示在地图上,现在我想为每个引脚存储一些附加信息,例如:

float lng = [[stationEnCours objectForKey:@"ssiphone_longitude"] floatValue];//that's how i retrieve it from web-service
float lat = [[stationEnCours objectForKey:@"ssiphone_latitude"] floatValue];//that's how i retrieve it from web-service

出于我的目的,我使用委托的这种众所周知的方法:

 -(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
    {
        NSLog(@"calloutAccessoryControlTapped");
//how to do to store additional informations

    }

但我有点受阻,我如何存储与每个引脚相关的附加信息,请帮忙,任何建议,示例代码,教程将不胜感激:)))))提前谢谢

actually, i have retrieved a lot of informations about service stations from web-service, they are here, i displayed for each Station a pin annotation to show it on the Map with a UIButtonTypeDetailDisclosure, now i want to store for each pin some additional informations like :

float lng = [[stationEnCours objectForKey:@"ssiphone_longitude"] floatValue];//that's how i retrieve it from web-service
float lat = [[stationEnCours objectForKey:@"ssiphone_latitude"] floatValue];//that's how i retrieve it from web-service

for my purpose, i use this well known method of the delegate :

 -(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
    {
        NSLog(@"calloutAccessoryControlTapped");
//how to do to store additional informations

    }

but i am some kind blocked, how can i store additional informations related to each pin, help please, any suggestions, sample code, tutorials will be appreciated :))))) thx in advance

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

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

发布评论

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

评论(1

£冰雨忧蓝° 2024-11-13 16:55:29

是的,在 MyLocation.h(实现 MKAnnotation 的类)中声明所有属性。创建注释时,在调用 addAnnotation 之前,请设置属性。

在 calloutAccessoryControlTapped 中,获取如下属性(示例使用上一个问题中定义的 MyLocation 中的属性):

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    MyLocation *myLoc = (MyLocation *)view.annotation;
    NSLog(@"calloutAccessoryControlTapped: enseigneDeLaStation = %@, distanceVersLaStation=%@", myLoc.enseigneDeLaStation, myLoc.distanceVersLaStation);
}

Yes, declare all your properties in MyLocation.h (the class that implements MKAnnotation). When creating annotations and before calling addAnnotation, set the properties.

In calloutAccessoryControlTapped, get the properties like this (example uses properties in MyLocation defined in your previous question):

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    MyLocation *myLoc = (MyLocation *)view.annotation;
    NSLog(@"calloutAccessoryControlTapped: enseigneDeLaStation = %@, distanceVersLaStation=%@", myLoc.enseigneDeLaStation, myLoc.distanceVersLaStation);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文