[英]How to know which annoation has been tapped?
I am doing mapview. 我在做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. 我已将此信息保存在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. 当用户点击标注中的detaildisclosure按钮时,这就是委托方法。
- (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. 从委托方法获得的MKAnnotationView *view
包含Annotation。 You can store all information in your MapLocation class you need to display. 您可以将所有信息存储在需要显示的MapLocation类中。
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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.