SMICK.NET | Website of Mike Smick Graphics and Web Developer

How to link to a GPS coordinate on a webpage using geo url

Since smart phones are all smartypants these days, many of them have preloaded map system or are hooked to Google Maps. And with the popularity of mobile sites, it’s nice to think we can share our locations with people to quickly find us on GPS.  I discovered through a few sources that you can actually link in a webpage or email a link to GPS coordinates.  This is pretty cool and I think has some use cases.

“Hey, come to our office open house party where we have hidden buried treasure! [inserts multi-line street address]”

Now my Nexus One is smart enough to detect some addresses on a page or email and send to Google Maps. But that doesn’t mean all phones are, nor does it mean that Google Maps is the recommended GPS app. If you were writing an email or a website that could help assist someone finding your place, why not link right to the location for GPS as well as typing out your address? And for good measure, underneath that you could link to the Google or Bing Map as well to give them choices. OR you could even use a QR code to link to it from a paper flyer. (Yeah you like that idea don’t you!)

Here’s how you write a GEO URI in HTML for use on a webpage:

<a href="geo:38.62464092991612, -90.18476128578186">go here</a>

But wait, that’s a fine bit of knowledge however, how does one get the coordinates to a location in the first place?

Good question! Is it something in Google maps you can easily get? Unfortunately it’s not an “out-of-the-box” feature of Google Maps, but I’m going to make it simple to get GPS coordinates using a quick Javascript hack on the Google maps webpage.

  1. Find your location on Google Maps, right-click on the map and choose “Center on this location”
  2. Paste this code snippet into the browsers address bar (all by itself) and press enter.
    javascript:void(prompt('',gApplication.getMap().getCenter()));
  3. You’ll get a popup that returns the GPS coordinates: (38.62464092991612, -90.18476128578186)
  4. Remove the parentheses and construct the geo url as I did above.
    <a href="geo:38.62464092991612, -90.18476128578186">go here</a>

That was the full HTML code. If you were writing an email to people, you’d want to write in Rich Text mode and then do a hyperlink to just the geo:38.62464092991612, -90.18476128578186 part.

So let’s try it together shall we? Crank start your mobile browser and… Here goes nothing!.. GPS LINK GO!!!

Note: If you tried to click that GPS link from your PC right now, it will likely fail because your home PC / laptop doesn’t have a GPS program to launch. So come back here with your phone and try it when you get a moment.

More Information / Sources

GEO URI Wikipedia Article
Javascript Google Map Coordinate Hack
Dive Into HTML5 Geolocation

One response to “How to link to a GPS coordinate on a webpage using geo url”

  1. Alex says:

    Hello, i’m the author of the “geo:” URI specification (RFC5870). Thanks for writing up this article, very well done – i do have a small comment on the format of the URIs you’re using on your text:

    The specification does not allow for a space between the comma and the latitude and longitude components, so the URI should be “geo:32,12” rather than “geo:32, 12”. Implementations might, however, still accept such URIs with spaces (but this behaviour is entirely depending on the application)

January 16, 2011 at 5:54 am | learning, webdev | 1 comment