W3C Geolocation API
TheW3C Geolocation API is an effort to enhance your web browsing experience by defining a Javascript API that lets your browser provide a requesting website with your geographical location (with your permission). One example use case would be an online service that shows you all the nearby restaurants (A browser-based version of FourSquare).
W3C Geolocation API is designed to be independent of the underlying location sources, i.e. it defines only the function interfaces and data structures, but does no dictate how the location information is obtained. Examples of location sources are Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs, as well as user input.
How does Geolocation Work?
Though the implementation is not specified, W3C Geolocation API is built on existing technologies, and is heavily influenced byGoogle Gears Geolocation API. In fact,Firefox’s Geolocation implementation uses Google’snetwork location provider.
Google Gears Geolocation works by sending a set of parameters that could give a hint as to your physical location to a network location provider sender, which is by default, the one provided by Google (code.l.google.com, at the time of writing). Some of the parameters are a list of mobile cell towers and their signal strengths, as well as a list of detected WiFi networks and their signal strengths. These parameters are encapsulated into a JSON message and sent o to the network location provider via HTTP POST. Based on these parameters, the network location provider can deduce your location. The exact algorithm is not revealed, but it could possibly by some weighted average triangulation.
I also want to touch a bit more on how WiFi networks can be used to detect your location. Remember the Google Street View cars that got intoa lot of trouble for collecting beyond the WiFi header information? These street view cars go around collecting WiFi information, such as their MAC addresses and correlate them to their physical location. These information is then fed into their database of WiFi networks and their physical location. Thus to find out your location, they only need to know which WiFi networks are nearby and to conduct a search in their databases.
Prevalence
At the time of writing, only Firefox, Google Chrome and Safari support W3C Geolocation API. One prominent website using the W3C Geolocation API isTwitter Locations.
Both Google Gears and Firefox have also put together some demos:
http://www.mozilla.com/en-GB/firefox/geolocation/
http://code.google.com/apis/gears/samples/hello_world_geolocation.html
Screenshots:

Firefox Geolocation Demo. Note that my browser would ask me for permission to share my location first.
W3C Geolocation API
Now let me give an overview of the API just to give a more complete picture. The API provides primarily 3 categories of location request:
- “One-shot” request
- Repeated requests – The API will automatically call a user-defined function whenever there’s a change in location
- Requests for a cached location
Examples (all lifted fromW3C Geolocation API Specifications):
function showMap(position) {
//Show a map centered at (position.coords.latitude, position.coords.longitude).
}// One-shot position request.
navigator.geolocation.getCurrentPosition(showMap);
function scrollMap(position) {
// Scrolls the map so that it is centered at (position.coords.latitude, position.coords.longitude).
}// Request repeated updates.
var watchId = navigator.geolocation.watchPosition(scrollMap);function buttonClickHandler() {
// Cancel the updates when the user clicks a button.
navigator.geolocation.clearWatch(watchId);
}
// Request a position. We accept positions whose age is not
// greater than 10 minutes. If the user agent does not have a
// fresh enough cached position object, it will automatically
// acquire a new one.
navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {maximumAge:600000});function successCallback(position) {
// By using the ‘maximumAge’ option above, the position
// object is guaranteed to be at most 10 minutes old.
}function errorCallback(error) {
// Update a div element with error.message.
}
10 Responses to “W3C Geolocation API”
[...] on the new Javascript APIs – HTML5 WebSockets, Drag n Drop, WebWorkers, Offline Storage, Geolocation API etc. In addition, HML5 Rocks also offers a Code Playground, where developers could experiment with [...]
[...] I’ve created a new page to give a quick overview of the W3C Geolocation API and how it [...]
[...] had announced the release of Opera 10.6. Among support for typical HTML5 enhancements such as Geolocation, Web Workers and Offline Applications, Opera 10.6 has also built in the ability to play WebM [...]
[...] Google will be able to deduce your physical location. Please refer to my short description of W3C Geolocation API page for the fundamentals. In addition to deducing your physical location, Google will apparently, also [...]
[...] factor on its own. Instead, I expect that Location based services would come to a head only when W3C Geolocation API takes hold. // – [...]
- Rumours: Facebook To Unveil New Geolocation Check-In Feature In The Coming Weeks « WebScanNotessays:
[...] of the technical stuff behind the Geolocation technology, I had put together a short description of W3C Geolocation API. // – [...]
[...] can only be assessed via Facebook application for iPhone or from touch.facebook.com for HTML 5 and geolocation capable mobile browsers, though they expect to make Facebook Places available to more regions and [...]
[...] with full-featured browsers, such as iPhones and some Android phones; it most probably made use of W3C Geolocation API to derive the location [...]
[...] GPS sources (for more info on how Geolocation info can be derived from Wifi, please refer to my writeup on W3C Geolocation API), and are expressed in the form of geo:URI standard in the embedding sms. // – [...]
[...] fine project. I mean, if it works, who cares if all interested implementors used the same backend? W3C Geolocatiion API is a good example – it’s basically a repackaged Google Gears Geolocation API, and it [...]






