Saturday, February 12, 2005


Google Maps bookmarklet to show Latitude and Longitude

Update: 2/7/05 I have not kept this bookmark up to date with changes in GMaps, so it no longer works. However I would now recommend using Gmap Extras which is a GreaseMonkey script that adds display of lat/long to Google Maps, and also allows for easy bookmarking by name of locations.

The Google Maps UI does not show you your current location, though such information is useful for any number of reasons. It does however provide a "link to this page" link, which does show you the current location in the status bar when you mouse over it.

Thus was born the following bookmarklet, which replaces the "link to this page" text with the actual location of the (centre of) the map. It prefers to show the latitude and longitude, but will show the query string if that's all thats available. To make space for this, it also removes the redundant text links for the Print and Email options - you can still click the icons to get these functions, so nothing is lost. The display is done every two seconds - so may be just slightly behind the map when it changes, and it is not updated dynamically whilst you are dragging the map around, but will catch up soon after you stop. If the link ever reverts to the "link to this page" again, simply rerun the bookmarklet. If the link shows a query string (such as "JFK" or "90210"), then double clicking the map will recentre it, and display latitude and longitude.

This bookmarklet has been tested on Mozilla and IE 6 SR1 - I guess it should work on other browsers such as Firefox and the older version of IE 6. I've tried to make it as robust as possible, but the compact style of bookmarklets does not make it easy to cover every eventuality. It does of course rely somewhat on Google not changing their page markup or link URLs in incompatible ways, but it makes no reference to the existing page's javascript, so should be fairly robust in that respect.

Drag this link to your links bar --> Lat & Long

(I couldn't get IE 6 SR1 to allow me to simply drag and drop the link, but I simply created it by hand and that worked fine.)

A number of other people have been seeing what they can do with bookmarklets on Google Maps, such as:

You might want to consider converting your bookmark to use the technique documented in "Part 6" of my Google Maps research which demonstrates how to use "state listeners" with Google Maps.

This change would remove the need for polling.

Wanted to let you know this is great! But it just stopped working on Firefox 1.5 version. Any ideas what changed?
Post a Comment

<< Home