Get a user's latitude and longitude
suggest change// The callbacks below are assigned before the browser invokes them.
// Geolocation requires a secure context and the user's permission.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationFailure);
} else {
console.log("Geolocation is not supported by this browser.");
}
// Function that will be called if the query succeeds
var geolocationSuccess = function(pos) {
console.log("Your location is " + pos.coords.latitude + "°, " + pos.coords.longitude + "°.");
};
// Function that will be called if the query fails
var geolocationFailure = function(err) {
console.log("ERROR (" + err.code + "): " + err.message);
};
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents