Java Reference
In-Depth Information
var coords = position.coords;
var latitude = coords.latitude;
var longitude = coords.longitude;
 
var message = "You're at " + latitude + ", " + longitude
 
alert(message);
}
 
function geoError(errorObj) {
alert(errorObj.message);
}
 
navigator.geolocation.getCurrentPosition(geoSuccess, geoError);
</script>
</body>
</html>
Save the page as ch8_example1.html and load it into your browser.
The page requires the user's consent in order to retrieve his or her geographical position. So the
first thing you will see is a prompt asking you to allow or deny the page permission to retrieve that
information. Every browser displays this request differently; Figure 8-3 is Chrome's request.
figure 8-3
If you allow the page to access your position, you'll see the latitude and longitude of your device or
computer displayed in an alert box. If you choose to deny access, you'll see a message similar to that
shown in Figure 8-4.
Search WWH ::




Custom Search