如何从iOS中的地图引脚获取位置

时间:2012-04-16 18:43:08

标签: ios mkmapview mkannotation

我正在使用MKMapView对象,我可以创建引脚并将它们放在地图上。我现在要做的是从引脚返回信息。例如在我的

- (MKAnnotationView*) mapView:(MKMapView *)mapView viewForAnnotation (id<MKAnnotation>)annotation

我创建了我的引脚并将它们设置在地图上。我也在创建用户点击引脚时使用的按钮。一切都运作良好。现在我的问题是当点击该按钮时如何从该点击的引脚获取信息?下面是我目前如何设置它的一个小示例代码。任何建议都将不胜感激。

- (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
}

非常感谢任何建议

2 个答案:

答案 0 :(得分:0)

您应该创建一个派生自MKPinAnnotationView的类,其属性为id<MkAnnotationView>。在上面的方法中,创建此新对象而不是MKPinAnnotationView,并将id<MKAnnotation>属性设置为传入的注释。

答案 1 :(得分:0)

不是设置标注的目标,而是响应委托方法

mapView:annotationView:calloutAccessoryControlTapped:

annotationView将具有带坐标的annotation属性。

相关问题