views:

1937

answers:

7

Hi guys, I'm stuck here again. I have a database with over 120 000 coordinates that I need to be displayed on a google maps integrated in my application. The thing is that and I've found out the hard way simply looping through all of the coordinates and creating an individual marker for each and adding it using the addOverlay function is killing the browser. So that definitely has to be the wrong way to do this- I've read a bit on clustering or Zoom level bunching - I do understand that theres no point in rendering all of the markers especially if most of them won't be seen in non rendered parts of the map except I have no idea how to get this to work.

How do I fix this here. Please guys I need some help here :(

+1  A: 

I've not done any work with Google maps specifically but many moons ago, I was involved in a project which managed a mobile workforce for a large Telco.

They had similar functionality in that they had maps which they could zoom in on for their allocated jobs (local to the machine rather than over the network) and we solved a similar problem which sounds very similar like yours. Points of interest on the maps were called landmarks and were indicated by small markers on the map called landmark pointers, which the worker could select to get a textual description..

At the minimum zoom, there would have been a plethora of landmark pointers, making the map useless. We made a command decision to limit the landmark pointers to a smaller number (400). In order to do that, the map was divided into a 20x20 matrix no matter what the zoom level, which gave us 400 matrix elements.

Then, if a landmark shared the same matrix element as another, the application combined them and generated a single landmark pointer with the descriptive text containing the text of all the landmarks in that matrix element.

That way there were never more than 400 landmark pointers. As the minion zoomed in, the landmark pointers were regenerated and landmarks could end up in different matrix elements - in that case, they were no longer combined with other landmarks.

Similarly, zooming out sometimes merged two or more landmarks into a single landmark pointer.

That sounds like what you're trying to achieve with "clustering or zoom level bunching" although, as I said, I have little experience with Google Maps itself so I'm not sure this is possible. But given Google's reputation, I suspect it is.

paxdiablo
+1 for using the word minion!
andrewWinn
+1  A: 

I suggest that you use a marker manager class such as this one along with your existing code. Marker manager class allows you to manage thousands of markers and optimizes memory usage. There is a variety of marker managers (there is not just one) and I suggest you Google a bit.

Salman A
+4  A: 

There is a good comparison of various techniques here http://www.svennerberg.com/2009/01/handling-large-amounts-of-markers-in-google-maps/

However, given your volume of markers, you definitely want a technique that only renders the markers that should be seen in the current view (assuming that number is modest - if not there are techniques in the link for doing sensible things)

DanSingerman
Thanks for the link - I had stumbled upon clusterer a few minutes ago but your posted url has great options - thanks again
Ali
+2  A: 

If you really have more than 120,000 items, there is no way that any of the client-side clusterers or managers will work. You will need to handle the markers server-side. There is a good discussion here with some options that may help you.

Update: I've posted this on SO before, but this tutorial describes a server-side clustering method in PHP. It's meant to be used with the Static Maps API, but I've built it so that it will return clustered markers whenever the view changes. It works pretty well, though there is a delay in transferring the markers whenever the view changes. Unfortunately I haven't tried it with more than 3,000 markers - I don't know how well it would handle 120,000. Good luck!

Chris B
I was thinking along the same lines - that with every zoom level or so I would have to parse my locations and output only those locations or cluster of locations that are viewable within the bounds of the visible screen. The thing is that I wish there was some kind of code or open project that would help me get started on it :(.
Ali
Chris B: Calculations involved in my tutorial are pretty heavy. If you have 120k marker you probably should precalculate the clusters for each zoom level. Otherwise zooming will become quite slow.I would be interested in seeing your code. Do you have it somewhere online?
Mika Tuupola
Chris B: Oh and forgot to mention that it would be good idea to fetch only markers / clusters which are in current viewport. Is your data in database or for example in KML file only?
Mika Tuupola
@Mike - I built a test map with 20,000 random markers, stored in a DB. Whenever the view changes, I send the bounds to the server, which gets the markers within the bounds, runs your clustering algorithm, and sends a group of cluster markers and/or single markers back to the client. It works pretty well except for when all of the markers are filling the view - that takes about 4 seconds to cluster. Unfortunately it's not public at the moment.
Chris B
@Mike - down to about 1 second :)
Chris B
A: 

If only there is something more powerful than JS for this...

Ok enough sarcasm : ).

Have you used the Flash Maps API? Kevin Macdonald has successfully used it to cluster not 120K markers but 1,000,000 markers. Check out the Million Marker Map: http://www.spatialdatabox.com/million-marker-map/million-marker-map.html

Map responsiveness is pretty much un-affected in this solution. If you are interested you can contact him here: http://www.spatialdatabox.com/sdb-contact-sales.html

Nael El Shawwa
find any of the above useful?
Nael El Shawwa
A: 

Try this one :

http://googlegeodevelopers.blogspot.com/2009/04/markerclusterer-solution-to-too-many.html

Its an old question and already got many answers , but Stackoverflow is more as reference i hope this will help anyone who searches for the same problem .

Hamza