I'm Aza Raskin @aza. I make shiny things. I simplify.

I'm VP at Jawbone, focusing on health.

 

Geolocation Redux and a JS Library

After the excellent feedback I got on my last geolocation blog post, I’ve updated the proposed geolocation API. More importantly, I’ve also created a pure Javascript library which you can use to start playing around with geolocation before we actually get it into the browser. This library provides exactly the same API as would be provided by the browser. Although it can’t offer GPS-quality data, it does provide a decent city-level geolocation based on your IP. You can get the library here, and there’s also a no-frills demo.

For quick hacking you can just include the following in your head tag.

<script src="http://azarask.in/projects/geolocation/MockGeolocation.js"><script>

The best way to get a feel for the API is to see some examples:

var g = new navigator.GeolocationRequest();
g.request( function(geolocation){
  alert( geolocation.longitude + ", " + geolocation.latitude );
})

This is the same example as we saw last time; it alerts the user’s current location. What’s new is that I’ve spec’ed out the object passed to the callback (I’ve borrowed some of the great work done for the GoogleGears Location API):

interface Geolocation {
  readonly double latitude;         // in degrees
  readonly double longitude;        // in degrees
  readonly double altitude;         // in meters, or null if no data.
  readonly double accuracy;         // in meters
  readonly double altitudeAccuracy; // in meters, or null if no data
  int timestamp;                    // time of the location read, in seconds since
                                    // the epoch
}

Everything here should be self-explanatory. As a commenter mentioned last time, it’s important to know when the last location reading occurred. Without it, for example, it would be impossible to reliably calculate the current speed of the browsing device. (Knowing such data gives developers all sorts of fun—we could have an onDrunkDriving DOM event for when the browser detects your moving at 60MPH and weaving!).

Let’s move on to something a bit more complicated.

var g = new navigator.GeolocationRequest();
g.request({
  error: function(e){ alert( e.message ); },
  success: function(location){
    alert( location.altitude + "+/-" + location.altitudeAccuracy );
  },
  desiredAccuracy: g.defaultAccuracy
})

Here’s the new stuff:
error takes a callback whose argument is an object. The only attribute the object must have is message, a human readable explanation of the error. The error object may have other attributes, as dictated by the particulars of the location-giving device.

desiredAccuracy is a string which can take one of three values: “exact”, “neighbourhood”, and “city”. In order, “exact” means to return a geolocation as precisely as possible, “neighbourhood” means to return a geolocation good to 1km, and “city” means to return a geolocation good to 10km. It’s unnecessary to include a “country” option because there are more accurate ways of knowing what country a user is browsing from than with a highly fuzzed lat/long (e.g., IP-based geolocation).

defaultAccuracy is a read only property of the GeolocationRequest object that contains the user’s globally-set preference for yielding location to content providers. If the user has opted to give all websites city-level access to their location, then a website requesting city-level information won’t cause the browser to prompt for permission. In the above example, the request is asking for the highest accuracy location that won’t prompt the user for permission. defaultAccuracy is null if the user has opted out of providing geolocation information.

That about wraps it up for the API. Full interface documentation is available.


Why not on window.navigator?

It’s tempting to attach the GeolocationRequest object to window, but it makes more semantic sense to place it on the navigator object (and, unfortunately, not just for the pun). The navigator object contains meta information about the browsing agent—browser version, os, language, etc—and geolocation information is just that. Looking at it from the other side, the window object should contain information that is tied to the current tab/window. Geolocation is independent of what tab/window you are looking at (unless, of course, you have an extremely large screen), and so should not be attached directly to window.


Geocoding API

I’m somewhat on the fence about whether to include geocoding as part of the fundamental GeolocationRequest API. The information is useful to web developers, and it is a boon to not require an extra Ajax call to perform geocoding. However, it’s going beyond the scope of the fundamental language of geolocation. To quote Arun Ranganathan, our standards hero here at Mozilla:

When coining new browser primitives exposed at the same level as DOM stuff, we essentially go with the simplest thing that developers can do that won’t break the web and that are possibly exposed on the given device. You’ll notice that there’s plenty of scope for more nuanced APIs on top of our primitive stack, and this has contributed for much of the boom on the web for third party encapsulations around basic browser primitives (Dojo, Prototype, jQuery, etc.)… latitude/longitude is the basic thing we should expose. These can be used with other services and providers (example: Google Maps) to obtain address information or proximity information based on latitude and longitude.

That aside, we don’t really have to choose. By designing the API right, we can upgrade to include geocoding at a later date, without breaking any code. Let’s see it in action:

var g = new navigator.GeolocationRequest();
g.request({
  error: function(e){ /* Handle error. */ ); },
  success: function(location){ alert( location.address.city ); },
  desiredAccuracy: "neighborhood",
  requestAddress: true,
  addressLanguage: "en-US"
})

You can get the library for the address-enabled API here. The address object interface is:

interface Address {
  // Any of the below can be null, if not known.

  readonly string streetNumber; // street number
  readonly string street;       // street address
  readonly string premises;     // premises, e.g. building name
  readonly string city;         // city name
  readonly string county;       // county name
  readonly string region;       // region, e.g. a state in the US
  readonly string country;      // country
  readonly string countryCode;  // country code (ISO 3166-1)
  readonly string postalCode;   // postal code
}

The full specification is available, if you are interested in such sundry documentation.


Interface

Based on a number of good suggestions from the last post, this is how I’m thinking the security UI should look:
Geolocation Security Mockup

RT @aza Geolocation Redux and a JS Library | Follow @aza on Twitter | All blog posts

View all 80 comments



Blair McBride

Looks good. I think it would more important to see this in Fennec (the up-coming mobile version of Firefox) than the desktop Firefox. But hopefully having APIs like this will make us see more GPS receivers in laptops – maybe even desktops too.

One question though:

What will webpages see if the user’s isn’t hooked up to a GPS receiver? ie, will navigator.GeolocationRequest be undefined? Or will it return null? Or will it return a full data structure with all values as null?

I think that part of the API is just as important, as most people won’t have any GPS data. But not having data is far different from just having a browser that doesn’t support geolocation.


    I would have to say maybe invest in a faster internet. If it is slow and you try to do two things at once then that is what usually happens.



Aza Raskin

@Blair: The hope is to have one web available everywhere. I.e., that the same JS APIs can be used on your mobile device and your computer. As for the not-hooked-up-to-a-GPS case, all we have to do is to have a number of fallbacks. The worst fallback can be a ping to Mozilla to do a geoip lookup. A better fallback can be to use wifi-based geolocation technology.


I’m not sure of a good solution for this, but when I glanced at the text labels on that security UI and thought “1 mile… 1 kilometer… oh wait, the first one must have been 1 *meter*…” and when I asked a couple U.S. friends, they confirmed that’s what they thought initially too.


Sounds like you need some i18n for your units of distance. :)



Aza Raskin

@Ryan/Ted: Ah, dear. Yes. Consider those units to be correctly localized. We can even have them in nautical miles and furlongs ;)


I have a hard time reading the person size for accuracy, as its the inverse of the region size. Maybe a little of both? That is, make the circles a little larger as the area increases, and the person a little smaller.

The radius thing seems vague to me. If it gives the center of the radius in each case, then of course there’s no difference. So what information is really given? If it’s a city name, or a zip code, or something like that… can you actually show what is sent? If it’s an area, and you happen to be right on the border, that could be nice to know — for example, I’ve had that problem when looking for something like a restaurant based on zip code. Or, what if the information is inaccurate? How can you check that? What if you want the information to be inaccurate? Like, you are going to be somewhere else later, and you want to get information about that area?

Some other little details… what if you don’t have exact information available? My laptop is not capable of knowing exactly where I am. Can I select my location on a map? From a list of locations I’ve been at before? Can the browser learn things, like when my externally-visible IP address is a certain value, it means I’m at the office.

As a user, I would probably be happier if there was a consistent UI for all the location-related things. That is, if the API you give is really hooked up to something fairly sophisticated that gives all these options.


    cmrheyborb619 on August 24, 2011 can I have the link please?



Aza Raskin

@Ian: Thanks for the graphic feedback. I’ve updated it also modulate the circle size. In terms of the radius thing, all it is doing is forcing an increase in the error. That is, if you select “neighborhood”, then Ars Technica with get back a lat/long that is good to within +/- 1km of your actual location. So Ars Technica might think you are .7km northwest of your actual location. At least for the first round of geolocation in the browser, you won’t get automatic access to geocoding so that there will never be the border problem you described.

The basic idea with the location api is to abstract, as you say, all the difficulties of actually getting your location. So on the backend, it will try GPS, wifi-based location, IP-based location, ESP, whatever it can to get your location as best it can. But as a user, you’ll never see that.



Ian

” I believe that location is such vital context, Powerbooks should come with GPS receivers pre-installed, with an easy software API. Developers would then write software to take advantage of it, and other computer makers would follow suit. Someday, a computer without GPS might seem as silly as a computer without a clock.” Bret Viktor

Nice to see that you are following him and extending some of the great ideas he’s proposed.



Aza Raskin

@Gregor: I work with Doug, so yes. I called him out in particular in my first blog post about geolocation.


I like the proximity granularity, but I would also like to have a duration UI selector. I might like to allow a webapp to get my location over a certain duration, but no more than that. I suppose I could navigate away from a webapp or shut down a widget, but it’s something to consider.


A more humane way to label proximity granularity would be to label the scale with the geolocation information itself. Instead of using

exact location
neighbourhood
city
nothing

as the scale, the browser would label the scale with each part of the address of the user’s location. For example, if the user was located in Office number 123 at Google’s headquarters, the scale would be:

Office 123
1600 Amphitheatre Parkway
Mountain View
California
USA

Users would then be able to say that they don’t mind an app knowing that they are in Mountain View, but telling the app that they are in Amphitheatre Parkway would be too much information.

The advantage of an address-based proximity scale is that it doesn’t use country- and language-specific terms, such as neighbourhood and city, but does use the address format familiar to users in each country.



Aza Raskin

@Jeff: That’s a phenomenal idea! I like it a lot. The biggest problem, though, is that geocoding data might not be available. For example, with a GPS you won’t know the user’s non-lat/long location information without a round-trip to a geocoding server. And even then, you might not be returned useful results. I think the solution I gave might be a good fallback mechanism… but any more thoughts about what happens when you only have access to lat/long?


If you only have the lat/long then you can still form a rough address. One can work out the city from a lat/long which would then give the country. If the lat/long is in the woods, a desert, or some other place not near a city, then the lat/long still gives the country, which the browser can then present as a simple “Nothing” or “USA” choice (if the user in the USA).

The browser can only present the location information that it has available. The user interface for the scale must be flexible, which is why I believe an address-based scale is more suitable. We are all used to dealing with incomplete addresses, or addresses that are less detailed than others. Using my Google headquarters address example, all of the following would make humane scales:

USA
Nothing

California
USA
Nothing

Mountain View
California
USA
Nothing

Amphitheatre Parkway
Mountain View
California
USA
Nothing

Another important interface issue is the level of detail from the human perspective. A pair of lat/long co-ordinates accurate to a metre is technically very accurate, but the name of the street the user is in is more informative and meaningful to people, even though it is technically less accurate. Users might also consider a street name more detailed than their numerical lat/long position because names are more meaningful to us than numbers, but you’d need to do some user testing on that.


Занимаюсь дизайном и хочу попросить автора http://www.azarask.in отправить шаьлончик на мой мыил) Готов заплатить…


Looks good. I think it would more important to see this in Fennec (the up-coming mobile version of Firefox) than the desktop Firefox. But hopefully having APIs like this will make us see more GPS receivers in laptops – maybe even desktops too.


Looks good. I think it would more important to see this in Fennec (the up-coming mobile version of Firefox) than the desktop Firefox. But hopefully having APIs like this will make us see more GPS receivers in laptops – maybe even desktops too.


    I don’t see ayhnting different with Safari 4 on my Mac, or on the browser on my Palm Pre (which is based on a slightly older version of WebKit than Safari 4). What am I supposed to see?



Sex

Looks good. I think it would more important to see this in Fennec (the up-coming mobile version of Firefox) than the desktop Firefox. But hopefully having APIs like this will make us see more GPS receivers in laptops – maybe even desktops too.


It retains mens belts cheap gucci belts cheap louis vuitton belts for men the new cheap desiger belts shape Stretch Jeans Slender gucci belts on sale September louis vuitton belts cheap Have you ever thought it was a method as one million U.S. dollars without sacrificing comfort;


    Re: nuembr one, I totally agree! EARN, the CA-based nonprofit I work for, helps low-income workers save money to invest in assets, including small businesses. I’ve been thinking of how cool it would be for an app to link CA residents up with our Savers’ businesses and reward them for being regular patrons!


C Beijing China mens belts NBA star center Yao Ming cheap gucci belts GHD can cry without pain, to the Court in the eyes of basketball cheap louis vuitton belts for men fans, but some irreducible on the possibility of cheap desiger belts the first born of the soul would have gucci belts on sale U.S. passports. louis vuitton belts cheap Yao and his wife returned to the United States MBT, where he plays for the Houston Rockets before the birth of her first child, which should eventually took place between May and July.


Very interesting publication


I think that’s a pretty neat idea. My current watch is a Timex that mimics a chronograph digitally but has both an analog and digital face: I can hide the digital part of it by pressing a button and leave the clean lines of a analog watch (which I prefer). Since I enjoy the benefits of digital for cycling and training and such, it’s nice to have that option.


yirmi üç yorum yapılmıştı sitene benle birlikte yirmi dörk oldu


difference. So what information is really given? If it’s a city name, or a zip code, or something like that… can you actually show what is sent? If it’s an area, and you happen to be right on the border, that could be nice to know — for example, I’ve had that problem when looking for something like a restaurant based on zip code. Or, what if the information is inaccurate? How can yo


Nice to see that you are following him and extending some of the great ideas he’s proposed.



py3r3str

hey
is it still working? I think I get not as precision data as i was getting few days ago.


thnks
goooooooooooood
min:)


This will work only in forefox ??


Users would then be able to say that they don’t mind an app knowing that they are in Mountain View, but telling the app that they are in Amphitheatre Parkway would be too much information.


thnks
goooooooooooood
min:)ااا


I like such topics


Easier on turns!

P.S. Please review icons


Hello There. I found your blog using msn. This is a very well written article.
I will be sure to bookmark it and return to read
more of your useful information. Thanks for the post.

I’ll certainly return.


article on this site very useful. thanks – Sedang mencari rumah minimalis ? baca artikel tentang Info rumah minimalis secara gratis


I’m super excited to see where it goes. I’ll keep an eye on your post.


Merely need to state your own post is really as amazing. The actual lucidity inside your set up is merely good as well as i will assume you are educated with this topic.


Purely, exceptional everything you do in this article. It can be satisfying to take a look people convey on the cardiovascular and your quality on this important information might be easily seemed. Exceptional submit and will enjoy your own foreseeable future update.


Great post! I?m just starting out in community management marketing media and trying to learn how to do it well resources like this article are incredibly helpful. As our company is based in the US, it?s all a bit new to us. The example above is something that I worry about as well, how to show your own genuine enthusiasm and share the fact that your product is useful in that case


Hrmm that was weird, my comment got eaten. Anyway I wanted to say that it is nice to know that someone else also mentioned this as I had trouble finding the same info elsewhere. This was the first place that told me the answer. Thanks.


Hey, just looking around some blogs, seems a pretty nice platform you are using. I m currently using WordPress for a few of my sites but looking to change one of them over to a platform similar to yours as a trial run. Anything in particular you would recommend about it?


Keep em coming. you all do such a great job at such Concepts. can t tell you how much I, for one appreciate all you do!


Hi webmaster, commenters and everybody else !!! The blog was absolutely fantastic! Lots of great information and inspiration, both of which we all need!b Keep em coming. you all do such a great job at such Concepts. can t tell you how much I, for one appreciate all you do!


Have you ever considered adding more videos to your blog posts to keep the readers more entertained? I mean I just read through the entire article of yours and it was quite good but since I m more of a visual learner,I found that to be more helpful well let me know how it turns out! I love what you guys are always up too. Such clever work and reporting! Keep up the great works guys I have added you guys to my blogroll. This is a great article thanks for sharing this informative information. . I will visit your blog regularly for some latest post.


Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I ll be subscribing to your feed and I hope you post again soon.


That fantabulous post this has been. Within no way seen this kind associated with useful post. I am grateful to you and anticipate much more associated with posts such as. Thank you very much.


Wow, this was a really quality post. In theory I d like to write like this too taking time and actual effort to make a good post. but what can I say. I procrastinate alot and never appear to get something done.


I admit, I have not been on this webpage in a long time. however it was another pleasure to see It is such an essential topic and ignored by so numerous, even professionals. I thank you to help making people more aware of possible issueExcellent stuff as typical.


The post is pretty interesting. I really never thought I could have a good read by this time until I found out this site. I am grateful for the information given. your writing is also very excellent. Thanks for nice post. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work.


Interesting topic for a blog. I have been searching the Internet for fun and came upon your website. Fabulous post. Thanks a ton for sharing your knowledge! It is great to see that some people still put in an effort into managing their websites. I ll be sure


Just what I needed. Thankyou I have been looking for this sort of information for ever. I have made note of your blog in order for me to read more on the topic.


i love your blog, i have it in my rss reader and always like new things coming up from it


I must tell you I am impressed. Very seldom do I encounter a blog that s both educative and entertaining. Just want to let you know that you have most definatly hit the nail on the head. Your thought is excellent. Thx is all I can say .


A powerful share, I just given this onto a colleague who was doing a little analysis on this. And he actually bought me breakfast as a result of I discovered it for him. . smile. So let me reword that: Thnx for the deal with! But yeah Thnkx for spending the time to discuss this, I feel strongly about it and love studying more on this topic. If attainable, as you turn into expertise, would you mind updating your weblog with extra particulars? It s highly helpful for me. Big thumb up for this blog put up!


I actually learned about nearly all of this, but with that in mind, I think it is still useful. Great job!


Hello I found your blog by mistake when i was searching AOL for this matter, I must tell you your blog is actually useful I also adore the design, which is cool that!


I see you put a lot of work on this site! Keep writing!


Although I am not a noob in the website industry, your site is truly unique and features some useful insights. Enjoy it fully! I, ll have entered my blogroll, I think it will give more value to the visitor.


An interesting dialogue is worth comment. I feel that you should write extra on this topic, it won, Aot be a taboo subject but usually people are not enough to speak on such topics. To the next. Hail


I was imprssed with the quality of the information on this website. There are many great resources here. I am sure I will visit this place soon.



Alex

Looks good. I think it would more important to see this in Fennec (the up-coming mobile version of Firefox) than the desktop Firefox. But hopefully having APIs like this will make us see more GPS receivers in laptops – maybe even desktops too. From Android APK


This is a great resource that you are providing and you give it away for free. I enjoy seeing websites that understand the value of providing a major resource for free. I really loved reading your post. Thank you!


Super blog post, I count on updates by you.


I was very encouraged to find this site. I want to thank you for this special read. I definitely enjoyed every bit of it and I have you bookmarked to check out new stuff you post.


I admire the valuable information you offer in your articles. I will bookmark your blog and my children check here often. I am quite sure they will learn lots of new things here than anyone else!


Finally, an issue that I want. I have searched for information of this caliber for the last several hours. Your site is greatly appreciated.


Thank you for another essential article. Where else could one get this kind of information in such a complete way to write? I have a presentation next week, and I am on the look for such information.


The beauty of these blogging engines and CMS platforms is the lack of limitations and ease of manipulation that allows developers to implement rich content and skin the site in such a way that with very little effort never see why the site tick all without limiting content and effectiveness.


This is the perfect blog for anyone who wants to know about this topic. You know so much it s almost hard to argue with you (not that I really want . HaHa). You definitely put a new spin on a topic that has been written about for years. Great stuff, just great!


This is a smart blog. I really do. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses. You have a design here that is not too flashy, but makes a statement as big as what you say. Great job, in fact.


What you say is absolutely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I also adore the images you put in here. They will fit well with what you re saying. Im sure you ll reach so many people with what you say.


Aw, this was a post that was really good. In theory I d like to write like this too taking time and real effort to make a good article . but what can I say . I procrastinate a lot and never seem to get something done that.


Far, this post is really sweet about this important topic. I am in harmony with the conclusions and are greedily looking forward to the update entry. Saying thank you will not just be sufficient, for the wonderful clarity in your writing. I will immediately grab your rss feed to stay informed of any updates. Wonderful work and much success in your business dealings! Please excuse my poor English as it is not my first language.


“%KW%”


Simply, admirable what you ahave done here. It is pleasing to look you express from the heart and your clarity on this significant content can be easily looked. Remarkable post and will look forward to your future update.


Leave a Comment