简体   繁体   中英

How to know which annoation has been tapped?

I am doing mapview. In my app there is code which gets current location of the user in latitude and longitude. Using this coordinates i am creating a soap request. In response i will get information(zip,city,state,country,coordinates) of locations. I have saved this information in NSDictionary.

This is the code for creating annotation.

MapLocation *annotation = [[MapLocation alloc] initWithCoordinate:location ownerInst:ownerInstitution];
    [mapView addAnnotation:annotation];
    [annotation release];


- (MKAnnotationView *) mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>) annotation {

MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
annView.pinColor = MKPinAnnotationColorGreen;
annView.animatesDrop=TRUE;
annView.canShowCallout = YES;

UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButton addTarget:self action:@selector(infoButtonPressed) forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = infoButton;


annView.calloutOffset = CGPointMake(-5, 5);
return annView;
}

This is the delegate method when user tap the detaildisclosurebutton in the callout.

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control

On the tap of detail disclosure button new view will be loaded. And in this new view, information which i retrieved from the server will be displayed.

Upto this everything is fine. I have more than one annotations in the map. But when particular annotation is tapped how will i implement the code to show the information (which i get from the server)related to that annotation.

I hope I am clear in expressing my problem. Feel free to ask further details.

The MKAnnotationView *view which you get from the delegate method contains the Annotation. You can store all information in your MapLocation class you need to display.

MapLocation *annotation = [[MapLocation alloc] initWithCoordinate:location ownerInst:ownerInstitution];
[mapView addAnnotation:annotation];
[mapView addAdditionalCustomInformation: SomeInfo]; //you need to write your custom methods for that ;)
[annotation release];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM