Firefox Universal Uploader Tweeting my Christmas letter
Dec 21

Gears Future APIs: Location API

Gears, Mobile with tags: , Add comments

I have spoken at a bunch of conferences in Europe this quarter. From the Future of Web Apps, and @mediaAjax in London, to JavaZone and JavaPolis in Oslo and Belgium. When I speak about Gears there, I get a lot of questions about Mobile Gears.

A lot of the features of Gears arguably make even MORE sense on a mobile device. Allowing Web developers to build applications for phones has taken off well thanks to the iPhone. Gears can help out in these high latency devices.

One very handy API to have would be a Location API (although it would be useful in other contexts too):

The purpose of this API is to provide means to fetch the location of a device running a Web browser with Gears.

The Location API is an abstraction for the various LBS APIs that currently exist on mobile platforms (GPS-based, network/cellid-based). The API consists of the Location class, which encapsulates various location attributes (latitude, longitude, etc), and also provides the means to query the platform for a location fix. This API also adds a new event type that is fired every time the location changes. Location implementations can be straightforward mappings to native LBS APIs (e.g the S60 Location Acquisition API) or have a more complex design that combines several location providers (e.g a GPS-based provider and a cell id-based provider) and returns the location from the most accurate provider at any given time.

Here is the API as a code example using it:

// Getting the object
var location = google.gears.factory.create( "beta.location", "1.0" );
// Setting up a callback to handle "location changed" events
location.onlocationstatechanged = function() {
   switch (this.state) {
     case 1:
     case 2:
      case 3:
          SetStatusText("Location accuracy:", this.accuracy);
          MoveMap(this.latitude, this.longitude);
      case 5:
         alert("Unknown state!");
// Initiate a fix. This leads to the onlocationstatechanged event handler being called exactly once for each
// of the "connecting" and "acquiring" states and one or more times for the "fixed" state (for the initial
// fix and every time the location changes, after that).
location.startLocationUpdates(); // async call, initiates fix (powers up GPS if needed, etc)
// Getting the last known location
if (location.latitude != -1 &&
    location.timeUTC > threshold) {  // the location info is valid and not very old
  Foo(location.latitude, location.longitude);
// Cancel the request. This leads to the onlocationstatechanged event handler being called for
// the "canceled" state. This call will power down the GPS HW / close HTTP connection
// (depending on the location providers that were in use).

I can imagine the fun games that I could write here, let alone the interesting business apps that could take the location context into consideration.

Other Future APIs

Disclaimer: This is early days, and who knows what the final API will look like, or if it will even make it. Do you have ideas for cool Gears that make the Web better? Let us know!.

7 Responses to “Gears Future APIs: Location API”

  1. Walou Says:

    Hi !

    thanks for post, very interesting.

    i’m a native mobile development, and I desire to know more about this. So, sorry for all questions follow :

    it is a free LBS API ? Should i subscribe to private API Key ? and how can i make it working in mobile device ?

    thanks a lot of

  2. Gerard White Says:

    I’m not a techie but was disapointed with last years Gphone announcement, with all the hype I expected Google guys to come up with something a bit more, well, you know.. Google. How about an off portal service for media, voip roaming, links into the HAM network, unlimited downloads, text and calls for a fixed price of say $10 per month with 75% of that revenue going back to rights owners.
    Have I missed something or is it all going to be there?

  3. Adnan Siddiqi Says:

    I need more Info about LBS based on Browser. can you guide me in this regard? also has gears implemented it yet? will this API work in every country or its for US only?


  4. miranda Says:

    very good
    buy xanax

  5. wholesale replica handbags Says:


  6. Craig Doremus Says:

    I have not worked with JavaScript on a mobile device, but I know that you can call Java from JavaScript (assuming a JVM is installed). If that is the case, can you do the same with a phone having a JVM and JSR-179/293 (Java Location API) implementation to obtain the phone’s location?

  7. Craig Doremus Says:

    Here the answer to my question: The JavaScript-Java connection depends on Java being implemented by the browser. This will most likely not be the case in a mobile browser.

    Another half-baked, hair-brained idea foiled again!

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: Type in the word 'cricket'