HTML & JavaScript Geo Location test

From munkjensen.net/wiki
Revision as of 15:40, 4 August 2022 by Admin (talk | contribs)

Inspiration:

Click the button to get your coordinates.

<script>
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;
}
</script>