如何显示具有相同纬度/经度的多个MKPinAnnotation? [英] How to display several MKPinAnnotation with same Latitude / Longitude?

查看:90
本文介绍了如何显示具有相同纬度/经度的多个MKPinAnnotation?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iPad App正在从数据库中检索地理对象.在此数据库中,某些对象具有相同的经度/纬度. 结果,在MkMapView中,我用相同的纬度/经度添加了多个MKPinAnnotation.不幸的是,只显示了一个,我想这是我添加的最后一个.

我如何只有一个MKPinAnnotation对象(对于给定坐标),当用户单击它时,我将为共享相同坐标的每个对象显示MKPinAnnotation?类似于Google Maps/Google Earth所做的事情,您单击主Pin,然后显示几个Pin.

任何帮助将不胜感激.

塞巴斯蒂安.

解决方案

您是否认为多个图钉在完全相同的坐标处彼此重叠显示?还是Apple可能会在相同的坐标处剔除额外的图钉?

无论哪种方式,我都建议更改坐标,以便可以清楚地看到它们是分开的.您所能做的就是使用CLLocation的distanceFromLocation:方法找到彼此非常靠近的所有引脚.一旦发现彼此之间的针脚之间的距离很小(例如<0.01),就可以在将它们的坐标添加到地图之前对其进行修改.您可以使它们围绕实际精确坐标形成一个小圆圈,而围绕该圆圈的角度则取决于该簇中的多少(例如,对于4个插针,将它们放置在0、90、180、270度).或者,您也可以只更改很小的纬度,以使图钉看起来在垂直线上相互叠置.

当用户点击单个引脚时,您也可以进行这种分离.也就是说,对于该引脚,请检查是否还有其他引脚非常靠近.如果有的话,请移除此图钉(或可能移除所有这些图钉),为圆形或垂直线上的所有图钉计算新位置,然后将图钉重新添加到地图中(并在需要时打开任何标注视图). /p>

一旦销以这种方式分开,用户将很容易点击各个销.

我不确定Google Maps/Google Earth如何处理此问题-您能描述一下还是提供截图?或提及一些可能导致这种情况发生的搜索字词.但希望上面的想法能给您一些尝试.

My iPad App is retrieving geographical objects from a database. In this database some objects have the same longitude / Latitude. As a consequence in the MkMapView I'm adding several MKPinAnnotation with the same Lat/Long. Unfortunately only one is displayed, I suppose it the last one I have added.

How can I have only one MKPinAnnotation object (for a given coordinate) and when user clicks on it I will display MKPinAnnotation for each objects sharing the same coordinates? Something similar to what is done by Google Maps / Google Earth, you click on the main Pin and then several Pin are display.

Any help will be appreciated.

Sébastien.

解决方案

Do you think that multiple pins are being displayed on top of each other when they are at the exact same coordinate? Or is it possible that Apple culls the additional pins at the same coordinate?

Either way, I would suggest changing the coordinates so that they can be seen to be clearly separate. What you could do is find all the pins that are extremely close to each other by using the distanceFromLocation: method of CLLocation. Once you have found that there are some pins that are a tiny distance (say < 0.01) from each other, then you could amend their coordinates before adding them to the map. You could make them form a small circle around the actual exact coordinate, with the angle around the circle determined by how many in that cluster (e.g. for 4 pins, place them at 0, 90, 180, 270 degrees). Or you could change the latitude only, by a very small amount, so that the pins appear to stack up on each other in a vertical line.

You could also do this separation when the user taps on an individual pin. i.e. for that pin, check if there are any other pins that are very close. If there are, remove this pin (or maybe remove all those pins), calculate new positions for all the pins in a circle or vertical line, then re-add the pins to the map (and open any callout view if required).

Once the pins have been separated in this manner, it will be easy for the user to tap on the individual pins.

I'm not exactly sure how Google Maps/Google Earth deal with this issue - could you describe it or provide a screenshot? Or mention some search terms that will cause it to happen. But hopefully the ideas above will give you something to try.

这篇关于如何显示具有相同纬度/经度的多个MKPinAnnotation?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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