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

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

问题描述

我有以下情况:
- 3个引脚与坐标相同,但不同的标题和信息
- 在地图上有ONY一个引脚

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 伊娃说会记住最后一次选择的注释是在委托方法增加它。

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.

此外,如果有注释的多个集群(3坐标为A,在5坐标B,4坐标为C等),那么你就需要保持在方法lastAnnotationSelected int数组和轨道,首先要确定选择什么样的群集,并获得下一批注该群集中选择。

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天全站免登陆