I am using the MKMapView object and I am able to create pins and place them on the map. What I am trying to do now is get the information back from the pin. For example in my
我正在使用MKMapView对象,我可以创建引脚并将它们放在地图上。我现在要做的是从引脚返回信息。例如在我的
- (MKAnnotationView*) mapView:(MKMapView *)mapView viewForAnnotation (id<MKAnnotation>)annotation
I create my pins and set them on the map. I am also creating buttons to use when a user clicks on the pin. All that works well and good. Now my question is when that button is clicked how do I get information from that clicked pin? Below is a small sample code of how I currently have it setup. Any advice would be greatly appreciated.
我创建我的引脚并将它们设置在地图上。我也在创建用户点击引脚时使用的按钮。一切都运作良好。现在我的问题是当点击该按钮时如何从该点击的引脚获取信息?下面是我目前如何设置它的一个小示例代码。任何建议将不胜感激。
- (MKAnnotationView*) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"location"];
annView.pinColor = MKPinAnnotationColorRed;
annView.animatesDrop = YES;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
UIButton* callout = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[callout addTarget:self action:@selector(loadDetails:) forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = callout;
return annView;
}
- (void)loadDetails:(id)sender
{
//TODO: Get pin coordinates or address and match it back to an array of available address to show details in a new view
}
Any advice is greatly appreciated
任何意见是极大的赞赏
2 个解决方案
#1
0
Instead of setting the target of your callout, respond to the delegate method
而不是设置标注的目标,响应委托方法
mapView:annotationView:calloutAccessoryControlTapped:
The annotationView
will have an annotation
property with the coordinate.
annotationView将具有带坐标的注释属性。
#2
0
You should create a class that derives from MKPinAnnotationView that has a property of id<MkAnnotationView>
. During the method above, create this new object instead of the MKPinAnnotationView and set the id<MKAnnotation>
property to the annotation passed in.
您应该创建一个派生自MKPinAnnotationView的类,该类具有id
#1
0
Instead of setting the target of your callout, respond to the delegate method
而不是设置标注的目标,响应委托方法
mapView:annotationView:calloutAccessoryControlTapped:
The annotationView
will have an annotation
property with the coordinate.
annotationView将具有带坐标的注释属性。
#2
0
You should create a class that derives from MKPinAnnotationView that has a property of id<MkAnnotationView>
. During the method above, create this new object instead of the MKPinAnnotationView and set the id<MKAnnotation>
property to the annotation passed in.
您应该创建一个派生自MKPinAnnotationView的类,该类具有id