Answers for "javascript get users location"

2

js get user location

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;
}
Posted by: Guest on November-06-2021
1

javascript get users location

if ("geolocation" in navigator) {
	navigator.geolocation.getCurrentPosition(function(position) {
		console.log("Longitude:", position.coords.longitude, "Latitude:", position.coords.latitude);
	});
}
Posted by: Guest on May-09-2022

Code answers related to "javascript get users location"

Code answers related to "Javascript"

Browse Popular Code Answers by Language