HTML & JavaScript Geo Location test: Difference between revisions

From munkjensen.net/wiki
(Created page with "[NOWIKI] <p>Click the button to get your coordinates.</p> <button onclick="getLocation()">Try It</button> <p id="demo"></p> <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 +...")
 
mNo edit summary
Line 1: Line 1:
[NOWIKI]
<pre>
<p>Click the button to get your coordinates.</p>
<p>Click the button to get your coordinates.</p>


Line 22: Line 22:
}
}
</script>
</script>
[/NOWIKI]
</pre>

Revision as of 18:41, 31 July 2022

<p>Click the button to get your coordinates.</p>

<button onclick="getLocation()">Try It</button>

<p id="demo"></p>

<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>