Hi everyone,
today I’ll be writing a small post about a problem that most people who write maps application deal with: add thousands of markers in you map. A known solution to manage your marker is GMarkerManager. However, today I read about the MarkerClusterer solution in GeoGoogleDevelopers Blog.
“MarkerClusterer collects markers into different clusters and displays the number of markers in each cluster with a label, creating new clusters as the map zoom level changes. The clustering algorithm is simple; for each new marker it sees, it either puts it inside a pre-existing cluster, or it creates a new cluster if the marker doesn’t lie within the bounds of any current cluster.”
The effect of using MarkerClusterer is shown in the picture below and library’s sample site:
The library works like magic. You just have to pass your array of markers to the MarkerClusterer constructor, and it ill take care of the rest. First, we have to import the MarkerClusterer JavaScript implementation file. Later, we create some markers, push into the array and call MarkerClusterer, as shown in the code snippet below.
It’s really awesome and straightfoward. Try it yourself.
See you,
—
Fernando
Do you know how to use MarkerClusterer in GWT? I have a GWT map and I really need to use this ! Thanks, Philip
Sorry philip, I don’t have too much experience in Google Maps API for GWT.
Maybe, if you have some way to use JavaScript manipulation for your map, the problem is solved.
[]’s
Fernando
i dont understand why when you create 300 markers the api displays 600 markers (sum of the marker’s values displayed) ??
thanks for your answer and sorry for my bad english !!
Sorry for this stupid question, i haved an error in my code, the function “init” was called twice…
Thanks anyway.
Bye
Hi, I have ported this to flash, if anybody wants the source it’s at
http://www.toruinteractive.com/stuff/MarkerClusterer_For_Flash.zip
I don’t do much open source development so I’m not sure where the best place to post the new source is. If anybody wants to take the code and put it in the appropriate place that would be great.
Sean
Hi,
How do you still leave retain the pop up window when i click on the marker?
Peter
Hi,
I have a listener in my map that intercept click on it and it add a marker. This event is fired also when i click on one of the marker created by markercluster.js.
Do you know how can I intercept if the click was made on the map or on the markercluster icon?
Hi all
I used the markerclusterer to display my photos. Maybe this example helps someone on how to use the clusterer.
Hi,
I would love to use this script, but i have a problem – i need to agregate markers not only by the density of them but also by the type of the marker – can any one poin me in some direction how to do it w/o inicializing 3 markerclusters ?