Multiple Annotations (IOS) Easiest way

蓝咒 提交于 2019-12-13 02:16:28

问题


Im using Annotations in IOS to display London Tube stations, but im looking at numbers and there are 280 or so. Whats the easiest way to do this? Individually or is there another option?

Cheers for all the advice

David


回答1:


The performance is good with 280 annotations, the appearance is not. You have to group them into clusters when the user zooms out.

One way to do it is:

  • Decide how many cluster annotations you want to show.
  • Split the screen in x*y tiles so roughly x*y =~ numClusters and x/y=480/320=1.5
  • Add a cluster annotation per tile (it's a normal cluster with an array containing 0 or more annotations).
  • Run the k-means algorithm:
    • Iterate all annotations and add each one to the closest cluster.
    • Calculate a new center for each cluster, which will be an average of the centers of all its members.
    • Empty each cluster.
    • Repeat until no cluster moves any longer.
    • Remove empty clusters, if any.

You end up with numClusters clusters positioned according to the annotation density.

You can also leave a number of normal annotations on their own if they are away from the clusters. Depends on how you want it to look.



来源:https://stackoverflow.com/questions/5978634/multiple-annotations-ios-easiest-way

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!