Geolocalizzazione con HTML5
Geolocation with HTML5 is used to locate a user's position, and it's much more accurate for devices with GPS, like smartphones. Internet Explorer 9+, Firefox, Chrome, Safari and Opera support Geolocation. Since this can compromise user privacy, the position is not available unless the user approves it.
Controllo abilitazione
if(navigator.geolocation){
alert('Geolocation enabled!');
} else {
alert('Geolocation NOT enabled!');
}
Ottenere le coordinate geografiche
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Your browser doesn't support geo location";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"Longitude: " + position.coords.longitude;
}
getLocation();