Geolocation in Firefox and Beyond

Advertisement:

POWERED by FUSION

In preparation for her keynote on the at the Web 2.0 Expo, Mitchell and I recently chatted about the “mobile web” misnomer. The misnomer is that there is going to be, long term, such a thing as a separate mobile web. There should only the one web (to rule them all), with different views into it, depending on the particular limitations or abilities of the device you are using.

One place I see the desire to separate the two webs is in geolocation. Location is often billed as the next killer-app of the mobile world, and people generally assume that it is a feature that will be bound to mobile devices. Yet, there are compelling reasons to have location information available to laptops as well: it is nice to have contextually relevant information available to me while working at a new coffee shop, traveling, or when farblonjet. At the core of the one-Web vision is the continuity of experience across all of my devices.

One of the symptoms of the the mobile-only location information is that to make something location aware, you have to deal with the large overhead of compiling an old-style application and porting it to all desired platforms. Then you have to figure out how to import the bits of the web you want into that application. It’s a pain.

What’s the solution? Adding geolocation to the browser, irrespective of whether it is on mobile or the desktop. That way writing a location-aware app is just writing a web-app with a little bit of new javascript magic.

I’ve been thinking about an API/spec, basing it on the work already done by Doug Turner and Ryan Sarver at locationaware.org. Here’s how it’s looking.

Simple call:

var geolocator = new navigator.GeolocationRequest();
geolocator.request(function(location) {
  alert( location.latitude + ', '+ location.longitude + ", " + location.accuracy );
});

That should be pretty obvious. The only bit that needs explanation is accuracy, which is a measure of how accurately the system is determining your location. Accuracy can be an enum with the these meanings: “exact”, “neighborhood”, “city”, “state”, “country”. I’ll come back to the reasoning behind doing it this way. However, it is worth thinking about also having an attribute location.errorInMeters (If you have thoughts on this, comment away!).

Complex call:

var geolocator = new navigator.GeolocationRequest();
geolocator.request({
  success: function(location) { /* We've got the location! */ },
  error: function(err){ /* There was an error getting location. */ },
  accuracy: "neighborhood"
});

Accuracy is the desired accuracy for the request. It’s there to make it easy for users and developers to see eye-to-eye on privacy and reliability. By putting accuracy into understandable, semantic, and quantized levels, we make it fast to understand what a web-app is trying to request. This way, if the user has globally allowed web sites access to their location at the neighborhood level, then any location request at the neighborhood or less-accurate level won’t cause the security/privilege UI to be invoked. And when the the request invokes the security/privilege UI, it can let the user know, in human-terms, what level of location information is being requested.

Here’s a quick mockup of the security UI. I haven’t put to much thought into ways of making this nicer yet, although I’d love something that gave a more visually compelling message of how much information you are giving out to websites.

Geolocation Security Mockup

I should be releasing a mock library for starting to play with this API soon. After that comes the real thing.