Multiple annotations (iOS) The easiest way

I use annotations in IOS to display stations on the London tube, but I look at the numbers and there are about 280. The easiest way to do this? Individually or is there another option?

Cheers for all the tips.

David

+1
source share
1 answer

Performance is good with 280 annotations; appearance is not. You must group them in clusters when the user is scaled.

One way to do this:

  • Determine how many cluster annotations you want to show.
  • Divide the screen into x * y tiles by approximately x*y =~ numClusters and x/y=480/320=1.5 x*y =~ numClusters x/y=480/320=1.5
  • Add a cluster annotation to each fragment (this is a regular cluster with an array containing 0 or more annotations).
  • Run k-mean algorithm :
    • Iterate over all annotations and add them to the nearest cluster.
    • Calculate a new center for each cluster, which will be the average center of all its members.
    • Clear each cluster.
    • Repeat until the cluster moves more.
    • Delete empty clusters, if any.

You fall into numClusters clusters arranged according to the density of annotation.

You can also leave a series of regular annotations yourself if they are outside the clusters. Depends on how you want it to look.

+6
source

Source: https://habr.com/ru/post/1479207/


All Articles