Thursday, August 21, 2008

Two new ways to location-enable your web apps

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.


  1. The 'AJAX API property' link seems to be incorrect.

  2. Fixed. Good catch, Cheeaun. Thanks!

  3. We’ve had the capability for over a year now. Any app can access any native (mobile) device information and send that to a Web server. We also have the capability to allow JavaScript to access local API's from the browser (Windows Mobile) without requiring an external API.

    More information and demonstrations can be found on our web site at and

  4. what if i want to do a server-side validation of the user location?

    is there any webservice also available?

  5. Sure. Go to and look under demos for examples of it working. One is real time GPS enabled search inside the mobile browser. We mash out to a local search engine, but it could go to any search engine.

  6. This comment has been removed by the author.

  7. Do you plan to release a REST API for CellID resolution or to add a new CellID query parameter to GMaps REST API ? We can already query the hidden CellID parameter used by the MyLocation service, but it's a hack and not official.

    Considering that, apparently, CellID data are user-generated content, it'd be fair to make them available under an open-source licence. And perhaps that you could provide CellID metadata datasets, or even better add your data to the OpenCellID datasets.

  8. This is a step in the right direction, however using IPs for geo-location will be very unreliable until there's regulation that forces ISPs to keep their databases up to date (after 8 months of service my home IP is still assigned to NJ although I am in San Diego!).

  9. At the beginning, Google Geolocation API has determined the location for only Americans, for the other it has returned "unknown". Later this service was advanced, but it often does not show results even for developed countries as yet. For such cases, there is a simple javascript extension to the Google API, which gives back the country of user.

  10. This comment has been removed by a blog administrator.

  11. Is there any server side solution for this?
    or a way to access this service on server side?

  12. Yes. The commercial version of the solution supports real time data encryption so we use a server side module (based off mod_gzip which we invented) to do the decryption.

    Remember this is not a service. You install the server module on your server and interact with your customers via the mobile thin client.

    Accessing the data on the server is easy. It arrives as a CGI environment variable

  13. The main 'AJAX API property' link destination appears to be gone. Does that mean the Google AJAX API method is no longer supported?

  14. Geolocation API fully support on Mozilla Firefox.

    var newLocation = + ", " +;



    For Opera & Chrome it only returns latitude & longitude.

    var lat = location.coords.latitude;
    var lng = location.coords.longitude;