MapKit多个引脚相同坐标,不同信息选择

发布于 2024-11-18 21:23:58 字数 189 浏览 2 评论 0原文

我有以下情况: - 3 个具有相同坐标但标题和信息不同的图钉 - 地图上只有一个图钉

可以在该图钉上点击多次,并且注释显示为: - 第一次点击->引脚 1 的注释 - 第二次点击->引脚 2 的注释 - 第三次点击->引脚 3 的注释 - 第四次点击 ->引脚 1 的注释

您对我应该如何实现它有什么想法吗?

I have the following situation:
- 3 pins with same coordinates but different title and info
- on map there is ony one pin

It is possible to tap multiple times on that pin and the annotation displayed to be:
- first tap -> the annotation for pin 1
- second tap -> the annotation for pin 2
- third tap -> the annotation for pin 3
- fourth tap -> the annotation for pin 1

Do you have any ideas how should I implement it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

通知家属抬走 2024-11-25 21:23:58

您可以实现 didSelectAnnotationView 委托方法,并根据最后一个“正确”选择自行选择“正确”注释。

如果地图上有这些注释并且其中一组,那么您可以保留一个int ivar来记住最后选择的内容注释是并在委托方法中增加它。

例如:

// In .h
int lastAnnotationSelected;

// In .m
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    int nextAnnotationToSelect = (lastAnnotationSelected + 1) 
                                     % mapView.annotations.count;

    id<MKAnnotation> nextAnnotation =
        [mapView.annotations objectAtIndex:nextAnnotationToSelect];

    [mapView selectAnnotation:nextAnnotation animated:YES];

    lastAnnotationSelected = nextAnnotationToSelect;
}

如果您还打开了 showsUserLocation ,那么您必须在该方法中添加对 MKUserLocation 的检查并跳过它(如果您愿意)并继续到集群中的下一个注释。

另外,如果您有多个注释簇(坐标 A 处有 3 个,坐标 B 处有 5 个,坐标 C 处有 4 个,等等),那么您需要跟踪 LastAnnotationSelected int 数组,并在方法中首先确定什么选择集群并获取要在该集群中选择的下一个注释。

You can implement the didSelectAnnotationView delegate method and select the "correct" annotation yourself depending on what the last "correct" selection was.

If you only have these annotations on the map and only one cluster of them, then you can keep one int ivar that remembers what the last selected annotation was and increment it in the delegate method.

For example:

// In .h
int lastAnnotationSelected;

// In .m
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    int nextAnnotationToSelect = (lastAnnotationSelected + 1) 
                                     % mapView.annotations.count;

    id<MKAnnotation> nextAnnotation =
        [mapView.annotations objectAtIndex:nextAnnotationToSelect];

    [mapView selectAnnotation:nextAnnotation animated:YES];

    lastAnnotationSelected = nextAnnotationToSelect;
}

If you also have showsUserLocation turned on, then you'll have to add a check for MKUserLocation in that method and skip it (if you want to) and go to the next annotation in the cluster.

Also, if you have multiple clusters of annotations (3 at coordinate A, 5 at coordinate B, 4 at coordinate C, etc), then you'll need to keep track of an array of lastAnnotationSelected ints and in the method, first determine what cluster was selected and get the next annotation to select in that cluster.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文