简体   繁体   English

如何知道已经使用了哪个注释?

[英]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.

相关问题 检测哪个 ImageView 已被点击 - Detecting which ImageView has has been tapped 如何判断UITableViewCell内的UISwitch何时被点击? - How to tell when a UISwitch inside of a UITableViewCell has been tapped? 如何检测使用RubyMotion敲击了UISlider? - How to detect that a UISlider has been tapped using RubyMotion? 如何检查已点击哪一部分的行? - How to check, that row of which section have been tapped? 有一种方法可以知道是否在iOS中点击了“为选项卡显示的视图”按钮? - There's a way to know if a View appeared for tabbar button has been tapped in ios? 如何知道仅基于应用程序捆绑包使用哪个证书对iPhone版本进行代码签名? - How to know which certificate has been used to code sign an iPhone build based on the app bundle alone? 如何知道图像已在SDWebImage中下载 - How to know image has been downloaded in SDWebImage TableView addGesture到UIImageView来知道哪个单元被点击 - TableView addGesture to UIImageView to know which cell was tapped 如何控制点击UIButton为使用Xcode进行UI测试中的下一个动作做好准备之后的时间 - How can I control the time after an UIButton has been tapped to prepare for next action in UI Testing with Xcode 如何检测哪个UILabel被窃听? - How to detect which UILabel was tapped?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM