Search code examples
web-servicesiosmkannotation

how to store information related of a pin in MKPinAnnotation


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


Solution

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