Howto: Geolocation in Firefox 3.5
Just a really quick how-to. I was playing around with geolocation services in Firefox 3.5. Its pretty easy to get the guessed location of the user but in my experience its far from accurate. I was located in Seattle while I’m actually located in Eugene Oregon. I imagine its attempting to locate me based upon my IP address but I imagine mobile devices will have better means to locate the position more accurately.
[Edit] Looks like the location is being determined by posting some data to Google (https://www.google.com/loc/json). Posting and retreived data formatted as JSON. Very interesting.
It also looks like flickr’s map is already using this to show interesting photographs in your location. Very cool idea.
Anyways, its pretty simple to do. Here’s some example javascript:
function locateMe(){
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(located);
}
else{
alert('Your browser is not supported');
}
}
function located(result){
alert('Latitude: ' + result.coords.latitude + '\nLongitude: ' + result.coords.longitude);
}
function locationFailed(result){
alert('Whoops, something broke.');
}
You can also get the accuracy of the result which is specificed in meters. There is also altitude, heading and speed to name a few. Learn more about the W3C Geolocation API Specification.