如何在MKPinAnnotation中存储与引脚相关的信息 [英] how to store information related of a pin in MKPinAnnotation

查看:85
本文介绍了如何在MKPinAnnotation中存储与引脚相关的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我已经从Web服务中检索了很多有关服务站的信息,它们在这里,我为每个站显示了一个图钉注释,以UIButtonTypeDetailDisclosure的形式显示在地图上,现在我要存储每个图钉都有一些其他信息,例如:

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

推荐答案

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

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

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

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

这篇关于如何在MKPinAnnotation中存储与引脚相关的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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