Have you wonder how do some map app provide functions to cluster icons/markers?


Here is one solution:



Inside the code:


MarkerCluster obj


    hide all markers first, calculate the markers distance, cluster them together in pixel distance and then show the clustericon


     add markers

     resetviewport

     redraw

     createClusters_

     addToClosestCluster_

     distanceBetweenPoints_

     if two markers are closer than 40000, cluster them together

     new Cluster


Cluster obj

ClusterIcon obj, extended from overlayview