After having thought and worked some more on the whereami extension (see also the post from yesterday and here's the installable file), there's now a privacy feature built in. The first time a site asks for your geolocation data, you can allow or disallow it permanently (kind of like with cookies). You can also later edit those options again via the preferences of the extension (in the add-ons menu of firefox). This gives you the control on which sites you want to use your geloc-data and on which not (currently, flickr, yahoo maps, google maps and local.ch are supported as of version 0.4.0)
Furthermore I cleaned up the API of the extension a little bit, so that any site can access the extension without having to enhance the extension itself. Of course also with the privacy option mentioned above. This means that if you have a website and would like to know some geolocation data of your users (which have the whereami extension installed), this can now be easily done.
First, you need the following code from common_user.js. You can copy/paste that into your javascript files. Then you just call āwhereami_getGeoLocation(callback)ā with a callback function. As soon as the extension got the data from plazes, it calls that function with the data. An example:
function showYourPosition() {
whereami_getGeoLocation(showdata);
}
function showdata(ll) {
alert("You're at " + ll.lat + ", " + ll.lon + " in " + ll.city);
}
Calling the showYourPosition() function would now just alert your position and city. Here's the fully working example, also with code for getting the position of your friends.
As extension and random websites can't directly communicate with each other, the two communicate via hidden DOM elements and firing events. The basic idea of this can be found on the mozilla developer wiki.
Maybe we will see some cool features with that in the future (and maybe I can finish the GPS support some dayā¦).