MapKit 多个引脚相同的坐标,不同的信息选择 [英] MapKit multiple pins same coordinates, different info selection

查看:26
本文介绍了MapKit 多个引脚相同的坐标,不同的信息选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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?

推荐答案

您可以实现 didSelectAnnotationView 委托方法并根据上次正确"选择的内容自行选择正确"注释.

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

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

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.

例如:

// 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 的检查并跳过它(如果您愿意)并继续到集群中的下一个注释.

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.

此外,如果您有多个注释簇(坐标 A 处 3 个,坐标 B 处 5 个,坐标 C 处 4 个,等等),那么您需要跟踪 lastAnnotationSelected 整数数组,并在方法中,首先确定选择了哪个集群,然后获取要在该集群中选择的下一个注释.

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.

这篇关于MapKit 多个引脚相同的坐标,不同的信息选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆