[英]How to know which annoation has been tapped?
我在做mapview。 在我的应用程序中,有一些代码可以获取用户当前的经纬度位置。 使用此坐标,我正在创建一个肥皂请求。 作为回应,我将获得位置的信息(邮政编码,城市,州,国家,坐标)。 我已将此信息保存在NSDictionary中。
这是用于创建注释的代码。
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;
}
当用户点击标注中的detaildisclosure按钮时,这就是委托方法。
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
在详细信息显示按钮上,将加载新视图。 在此新视图中,将显示我从服务器检索到的信息。
到目前为止,一切都很好。 我在地图中有多个注释。 但是,当点击特定注释时,我将如何实现代码以显示与该注释相关的信息(从服务器获取)。
我希望我清楚地表达我的问题。 随时询问更多细节。
从委托方法获得的MKAnnotationView *view
包含Annotation。 您可以将所有信息存储在需要显示的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.