how to store information related of a pin in MKPinAnnotation

依然范特西╮ 提交于 2019-12-12 05:54:46

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/5949598/how-to-store-information-related-of-a-pin-in-mkpinannotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!