15 August, 2006

A simple Google Maps mashup

Well I mentioned a couple of days ago that I was putting together a Google Maps interface to display the Local Heritage Initiative data on behalf of MySociety. As is the way with these things it turned out to be a bit more complex than I expected, but I've finally got something useable turned out.

There were several problems to surmount.


  1. Firstly, the new Google Maps Geocoder doesn't currently work from UK postcodes, presumably due to Royal Mail PAF licensing issues. Whatever the reason, it meant I had to find someone with access to PAF data to add a latitude and longitude to every record and wait for that task to be completed.

  2. Next, simply loading and processing the data from XML files takes 10-15 seconds, depending on computer speed. It's unacceptable to have a web page hang around for that length of time apparently doing nothing, but by (a) showing the map before loading any data, and (b) displaying an updating "loading..." status to the user, that problem was soon minimised.

  3. Finally, there are approximately 2,700 projects to map. At a zoomed-out view of the whole of the UK that's simply a couple of orders of magnitude more than needed. Although there are a number of strategies for handling too many points in Google Maps, none of the simple solutions suited me. The best solutions all assumed a database backend, but for the purposes of this project everything was stored as XML, loaded once at document startup and then processed dynamically on the client.



I tried developing a couple of "clustering" algorithms, so that at higher zoom levels I could display a marker (preferably in a different size/colour to the standard one) with an info box of (eg) "This marker represents 120 projects, please zoom in to see them in detail". However after a couple of false starts it became clear that this functionality was going to take some time to implement correctly, and there was a need to get something online as soon as possible.

So in the end I created a compromise. At lower zoom levels, when large chunks of the country were visible, I simply wouldn't display anything at all (other than a message requesting the user zooms in). Once the zoom level rose to displaying approximately 30km on each side then I'll create marker pins for only those projects currently displayed. This seems to work reasonably well, although if you were to scroll around the whole country without ever zooming out there would eventually be several thousand markers for the browser to keep track of. C'est la vie.

If you want to see the finished product (well not really finished, but published) it's here: MySociety / Local Heritage Initiative / Google Maps mashup. If you're interested in the raw data that's also available.

0 Comments:

Post a Comment

<< Home