Thoughts on software and life.

Wednesday February 9

Google Maps and Bookmarks

Google Maps has some of the most impressive DHTML I've ever seen, and I hope they set a precedent for future web applications to come. However, there is one little problem that I've noticed: Google Maps forces me to take the extra step of clicking "Link to this Page" before I can bookmark the map I'm looking at. There is a very easy solution to this problem that I'd like to share with the kind folks at Google.

Each time you move the map, Google Maps loads a new page in a hidden iframe with the state of the map. This allows you to use the back back button to go back to the previous map. Clever stuff, Google, except for one thing - you can accomplish the very same thing without hiding the state in a place where it won't be included when I bookmark the page, or copy or drag the URL somewhere.

The solution is this: each time you move the map, the script should set the location of the page to the current location plus an anchor, such as "#spn=0.018311%2C0.034092". Now if I bookmark the page and re-visit it, the script can read this state by parsing the URL of the page to extract the state and use it to update the map.

This solution will also allow the back button to continue to work with just one extra step. When the user hits the back button, the browser will change the location of the page to the previous anchor. Your script won't be notified when this happens, so you just have to set a timer to call a function every 100ms or so which checks if the URL has changed, and if so parses it and re-updates the map.

I know what you're thinking - polling the URL == Evil Hack, but calm down. This adds like four lines of code, and one string comparison doesn't even move the dial on the CPU usage while polling. It's a worthy compromise to support bookmarking.

As I write about this idea I'm testing it in Firefox and Safari and it works - I assume it will work on IE too but I'll have to wait til I am near a PC to find out. If so I'll post the sample code later on.

Posting your comment. Please Wait...