gpt4 book ai didi

ios - 如何从 iOS 中的 map 针获取位置

转载 作者:行者123 更新时间:2023-11-28 17:34:44 24 4
gpt4 key购买 nike

我正在使用 MKMapView 对象,我能够创建图钉并将它们放置在 map 上。我现在要做的是从 pin 中获取信息。例如在我的

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

我创建了图钉并将它们设置在 map 上。我还创建了用户单击图钉时使用的按钮。所有这些都很好用。现在我的问题是单击该按钮时如何从该单击的 pin 获取信息?下面是我目前如何设置它的一个小示例代码。任何建议将不胜感激。

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

非常感谢任何建议

最佳答案

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

mapView:annotationView:calloutAccessoryControlTapped:

annotationView 将有一个带有坐标的 annotation 属性。

关于ios - 如何从 iOS 中的 map 针获取位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10179763/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com