HTML & JavaScript Geo Location test: Difference between revisions

From munkjensen.net/wiki
mNo edit summary
mNo edit summary
Line 6: Line 6:
<button onclick="getLocation()">Try It</button>
<button onclick="getLocation()">Try It</button>


<p id="demo"></p>
<p id="ShowLatLonHere"></p>
 
</html>
</html>
<pre>
<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>
</pre>

Revision as of 15:42, 4 August 2022

Inspiration:

Click the button to get your coordinates.