开发者

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 wi开发者_运维技巧ll 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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜