views:

43

answers:

2

I have a website with around half a million geocoded locations in a database. I want people to be able to search for these via a map. Obviously, that's far too many for a standard Google (or, for that matter, Bing) map display, even when using something like MarkerClusterer.

What I want to do, therefore, is dynamically load the map data as people scroll around on the map so that there are never too many icons, or too much data, loaded at once. Here's an example of a site which already does something like this:

http://www.globrix.com/property/buy/wr11%203dl?ns=true&rd=1&hits=10&br=buy&qt=wr11+3dl&keyword_field=

Unfortunately, I'm not a skilled enough javascript programmer to reverse engineer that code! So I was hoping that there might be an open source project which I can use or adapt instead.

I've mostly used Google maps in the past (and the site currently uses Google maps for small-area search), but I'd be equally happy with Bing if that's easier. The backend is all in PHP.

Any suggestions?

A: 

This is something that I have done in the past, and its fairly simple. To begin with, you must use some kind of marker manager. A marker manager is a utility class that shows and hides markers depending on the portion of the map that is visible. This saves browser memory and improves performance. When using a marker manager, do not directly add markers to the map, add them to marker manager.

Next step, you need to hookup a function for the map.moveend event. This event is fired when user drags the map or zooms in/out. Every time this happens, the visible area changes. So, at this point, you just need to "add" the markers that should be visible to the map via marker manager. The marker manager then decides when to show and hide the newly added markers.

Sending marker data for half a million markers is not practical, so you must write an AJAX script, or use the GDownloadUrl function that fetches markers that should be visible when the visible area changes. For this you need a server side script that accepts (latitude, longitude) of the top left and bottom right corner of the visible area and returns the marker data in XML or JSON format.

Salman A
Reason for downvote?
Salman A
Not sure why. Your response assumes usage of the v2 API. I'd take a look at v3. Only markers in view get rendered. Keeping millions of markers in memory is still hefty, even if they aren't getting rendered.
broady
A: 

Listen for the 'idle' event on the Map.

You'll want to do some sort of spatial query, using the bounds of the Map.

Also, consider using Fusion Tables: http://google.com/fusiontables

broady