gpt4 book ai didi

ios - 在 MKMapView 上设置多个引脚,并让 Callout View 显示正确的信息?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:49:50 26 4
gpt4 key购买 nike

我有一个对象数组,其中包含 map 上每个图钉的信息。我可以使用 [mapView addAnnotions:array]; 将它们及其各自的坐标添加到 map 上。但是当涉及到选择一个引脚,然后显示该特定引脚的标注 View (使用正确的引脚位置和我的阵列中的正确信息)时,我迷路了。我也不完全了解 Callout View 如何针对多个引脚工作。我试过查看 Apple 示例代码,但没有太大帮助,谷歌搜索问题也无济于事。

简单版本:您应该如何在 map 上放置多个图钉,并在选择图钉和调用标注 View 时区分它们?

编辑:例如,iPhone 上的 map 应用如何显示企业的多个位置,当您点击它们时,会出现正确的名称和指向该企业的链接。

最佳答案

试试这段代码

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

static NSString *identifier = @"MyLocation";
if ([annotation isKindOfClass:[MNMyLocation class]]) {

MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [atmLocatorMap dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
} else {
annotationView.annotation = annotation;
}

annotationView.enabled = YES;
annotationView.canShowCallout = YES;
//annotationView.image=[UIImage imageNamed:@"arrest.png"];

return annotationView;
}

return nil;

关于ios - 在 MKMapView 上设置多个引脚,并让 Callout View 显示正确的信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11787798/

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