Geolocation API in Firefox 3.5

With the relatively new 3.5+ release  comes a new Geolocation API that enables geographical positioning of the browser client. Positioning is done through an array of means:

“Common sources of location information include Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs”

This functionality was earlier available through 3rd part solutions such as Google Gears, but now it is natively supported in Firefox.

The key function is: navigator.geolocation.getCurrentPosition()
If you have Firefox 3.5+ you may test the Geolocation API here (please let me know if the result is correct).

I also make use of the API in my geographical chat/game Zapin (in Swedish, but have a look).

Here is the javascript that makes it happen:
var oRequest = new XMLHttpRequest();
var sURL = "geodecode.php?lat="+position.coords.latitude+"&lon="+position.coords.longitude;

oRequest.open("GET",sURL,false);
oRequest.setRequestHeader("User-Agent",navigator.userAgent);
oRequest.send(null)

var MyAdress = 'Time:' + position.timestamp + '
Latitude:' + position.coords.latitude + '
Longitude:' + position.coords.longitude + '
Accuracy:' + position.coords.accuracy + 'm
Altitude:' + position.coords.altitude + oRequest.responseText;
document.getElementById('adressField').innerHTML = MyAdress;
}

if (navigator.geolocation) {
// Geo request
navigator.geolocation.getCurrentPosition(GeoDecode);
}

Popularity: 5% [?]

Comments are closed.