var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(function(position) {
console.log("Longitude:", position.coords.longitude, "Latitude:", position.coords.latitude);
});
}
geolocationSupported();
function geolocationSupported() {
if (navigator.geolocation) {
console.log("Geolocation is supported by this browser :)");
getCurrentLocation();
} else {
console.log("Geolocation is NOT supported by this browser :(");
}
}
function getCurrentLocation() {
navigator.geolocation.getCurrentPosition(function(result) {
result.coords.latitude; // latitude value
result.coords.longitude; // longitude value
});
}