Two new ways to location-enable your web apps

August 21, 2008

Link copied to clipboard

We just launched two new ways to give your web apps free and secure access to a user's location, without requiring that user to enter it manually.

First, there's the AJAX API property that provides a simple way to get an approximate, region-level estimate of a user's location based on their IP address. It's as simple as referencing google.loader.ClientLocation, which is made available using the Google AJAX API Loader. This API does not require users to install any client-side software. You can see this new AJAX API in action as part of the 2008 US Election gadget -- the "News by State" will show local news for the state associated with the user's IP.

Second, the Gears Geolocation API provides a way to get a more precise estimate of a user's location. On mobile devices with Gears installed, the Geolocation API can use the cell-ID of nearby cell towers or on-board GPS (if either is available) to improve the postion fix. In the near future, we'll be adding data from your WiFi connection to improve accuracy even further, on both desktop and mobile. In all cases, Gears takes care of assimilating the results from each source and returning the best available position estimate.

The Geolocation API has two JavaScript methods: getCurrentPosition() makes a single, one-off attempt to get a position fix, while watchPosition() watches the user's position over time, and provides an update whenever the position changes. Both methods allow you to configure which sources of location information are used. Gears also keeps track of the best position fix obtained from these calls and makes it available as the lastPosition property. This is a simple way to get an approximate position fix with low cost in terms of both network and battery resources.

The privacy of users' location information is extremely important. The first time your site calls the Geolocation API to request a user's location, that user will be shown a permissions dialog where they can choose to allow or deny your site access. Users can change that decision at any time via the "Gears settings" dialog in the browser menu. Google does not keep location information about users when your site uses the Geolocation API.

To use the Geolocation API your users may need to install the Gears browser plugin, a simple process on both desktop and mobile. The Geolocation API is available on platforms currently supported by Gears, including Internet Explorer, Firefox and IE Mobile (selected devices only). For users to be able to use location-enabled features on mobile they will need a Windows Mobile device that supports GPS or cell-ID lookup (for example the Samsung BlackJack II and the HTC Touch Dual, see list of supported device models in our FAQ). We are working hard to bring Gears to more mobile platforms soon. You can download and install Gears at Or try out some of the first location-enabled mobile web apps using Gears.

Like the rest of Gears, this new Geolocation API is open source. We're also doing our best to work with existing and emerging standards. Gears now implements the current editor's draft of the W3C Geolocation specification, which we've helped to define in collaboration with Microsoft, Mozilla, and others. We're committed to continued collaboration around the emerging HTML5 standard and the APIs specified by the W3C Web Applications Working Group. The goal for Gears is to advance browser capabilities, and part of that is helping define future web standards.

If you're interested in providing feedback or contributing to Gears, there's more info on the project website. There's also an AJAX APIs discussion group -- we're anxious to hear what you think.