开发者

Multiple Annotations (IOS) Easiest way

开发者 https://www.devze.com 2023-03-05 04:22 出处:网络
Im using Annotations in IOS to display London Tube stations, but im looking at numbers and there are 280开发者_开发百科 or so.

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消