Google Maps Geolocation Bookmarklet

I’ve been in Europe this week talking to French and German press about Firefox 3.5, and it’s been great to see all the excitement there is over here for the upcoming release.

One feature I’ve been talking a lot about is our support for Geolocation. I think that once Firefox 3.5 gets out there and sites realize they have a (privacy- and user-control-respecting) way to ask their users for their location in the world, all kinds of great services will show up. Flickr already has a photos-near-you feature, for instance, and I imagine mapping sites, restaurant reviews, and others are hot on their tails.

So I’m sure, in short order, that this won’t be necessary. In the meantime, if you’re running one of the Firefox 3.5 Release Candidates, you can use this bookmarklet to inject your current location into the google maps search box, so that you can base searches off your current location:

javascript:function sv(s){document.querySelector("#q_d").value=s};sv("Checking...");navigator.geolocation.getCurrentPosition(function(a){c=a.coords;sv(c.latitude+"%20"+c.longitude);document.forms.q_form.submit();},function(){sv("Rejected!")});

If you haven’t used a bookmarklet before, it’s easy. Open up your bookmark manager, decide where you want to put this (I like to have them on my bookmarks toolbar, since I use them a lot), and create a new bookmark. When it asks for a location, put in the code pasted above. Now, when you’re on the google maps site, click the bookmark to jump to your current location (after, of course, giving your consent).

This bookmarklet is specific to google maps (but I bet you can hack it!), and it certainly requires you to be using a modern browser with support for these features.  If you don’t have the latest Firefox yet, you can become part of our early testing community by downloading a copy now.

[Update: Changed the bookmarklet code a little to give some feedback immediately by letting you know it’s checking. I bet someone out there has already made a version of this that’s half as long, and twice as powerful. Comment!]

6 thoughts on “Google Maps Geolocation Bookmarklet

  1. I must admit I haven’t actually looked, but I’d like something a bit the other way around (especially if more sites actually start using this). Pretty much all the time I’m on the internet I’m either in front of a chunky desktop computer at home, or at work – the computers don’t move. Geolocation on both computers goes from the IP, and locates me somewhere in central London, miles away from where I am (and miles across a dense city at that).

    It would be good if I had a dummy Geolocation back-end where I could point to my location, and have it use that for geolocation.

  2. And in Fennec, can the geolocation use GSM based info for crude localisation when you don’t have GPS ?
    The Windos Mobile version of google maps does that, and there’s a sample of how to do it on code project. That sample uses the hidden google api google maps itself relies on to tranform the GSM info into localisation though, which certainly isn’t very clean if you don’t have proper autorisation from Google to do it.

  3. NB: Even without the google API, they are some open database on the web to do the same, just probably quite less precise, and also even without that part the sample is still very useful to show how to get that cell info from the phone, the solution to do that is very hackery on windows mobile.

  4. Hmm, not working for me. I’m fairly sure I did it right? Oh well, guess I’ll stalk you guys with itinerary suggestions the old-fashioned way… using a couple of different tabs. 😉

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s