Aside from the HTML5 canvas (which we all know to be the greatest thing since sliced bread), one of the cool new kids on the modern-browser block is the Geolocation API; or rather, the ability for your browser to retrieve geographic positioning information using JavaScript. While technically Geolocation is not actually part of the HTML5 spec, it’s mentioned so often in conjunction with HTML5 that it’s hard to separate the two.

When we look at the web browser landscape, the native support for geolocation is beginning to find its way into mainstream applications at a slow and steady pace. How many of us encounter the “Site awesomedomain.com would like to use your current location, accept?” as we browse the web on our mobile (and even desktop) devices. I know I have. How does the adage go? Location, location, location!

Of course, you’re welcome to accept or deny the request, and leave it up to the application on how best to deal with your denial. The API specification explicitly states that the user’s permission must be sought and obtained before proceeding. The browser will natively take care of this, and a message will either appear as a popup box, or at the top of the browser (implementation is browser specific) requesting your permission.

Geolocation Sources

A number of different sources can be tapped into to attempt to obtain the user’s location, and each has their own varying degree of accuracy.

Google Gears provided geolocation support for older and non-compliant browsers as a Gears plugin, and Google Chrome (which implements Gears natively) also support the plugin. The Google Gears Geolocation API is incompatible with W3C Geolocation API.

A desktop browser is likely using nearby wifi signals, which depending on the number of available signals, can affect the overall accuracy of your position. Your IP might also be routed through varying firewalls or proxies and may ultimately report your position in a different state, or even country! Often, however, multiple wifi signals can be used to triangulate final position and can be fairly accurate.

It should be noted that many access points (including your own home network) might already have their positions stored in publicly accessible databases maintained by Google, Microsoft, Apple, etal. If you are surprised by this, you should not be. When Google creates a street view, they drive around all the streets and log the SSIDs they encounter and where they are located. From this information, they have created a very rich database of publicly visible access points. Google explains why they collect wifi data.

Most mobile devices also incorporate GPS chips, which provides the most accurate readings. However, accuracy degrades as users move indoors (thus requiring wifi access points). If your device can’t determine your location from GPS or wifi it will fallback to cell tower triangulation. This method is the least accurate and will typically provide access within 1000-3000 meters.

Geolocation Use Cases

Of course, the API can be used for more than simply plotting a position on a map (although this in itself can often be quite useful). The specification itself annotates a list of potential use-cases:

  • Find points of interest in the user’s area
  • Annotate content with location information
  • Show the user’s position on a map
  • Provide turn-by-turn route navigation
  • Alerts when point of interest are in the user’s vicinity
  • Up-to-date local information (i.e. weather)
  • Location-tagged status updates in social networking applications

A hypothetical situation might be you organize response teams to remove gang related graffiti. By crowd-sourcing taggings, you not only significantly increase the number of graffiti reports, but by geo-tagging the submitted photos, you can get a more dynamic picture of where your “hotspots” are and divert resources accordingly.

Final Word

Geolocation is a young but promising part of the modern-browser scene. Used in conjunction with some of the other emerging browser technologies, you can create compelling “context-aware” experiences for your users or customers. Knowing the location of your users can help boost the quality of your site and the speed of your services (search results paired back to smaller geographic region, for example).