I’m working on a project right now where we make use of the Google Maps API to display various information on Google Maps. One page calls for a view of all golf courses in Sweden. To my surprice there are actually quite a few of them, closer to 500 golf courses. When you position lots and lots of markers in a small area of a map it can get quite cluttered and eventually the map starts to load painfully slow.
So with this in mind I set out to find a way to avoid this problem. I’ve seen on other sites markers that change depending on what level of zoom you’re currently in and a quick search on Google gave me the answer I was looking for. Cluster markers. Cluster markers is not a part of the Google Maps API but are supplied by third party developers. I went through a couple of different solutions but finally choose to use ClusterMarker by Martin Pearman.
ClusterMarker detects any group(s) of two or more markers whose icons visually intersect when displayed. Each group of intersecting markers is then replaced with a single cluster marker. The cluster marker, when clicked, simply centers and zooms the map in on the markers whose icons previously intersected.
The ClusterMarker API is well documented and really easy to implement and use.