HTML & JavaScript Geo Location test: Difference between revisions

From munkjensen.net/wiki
mNo edit summary
mNo edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
<pre>
=== '''Inspiration:''' ===
<p>Click the button to get your coordinates.</p>
* [https://www.mediawiki.org/wiki/Adding_JavaScript_to_Wiki_Pages Adding JavaScript to Wiki Pages] at mediawiki.org
* [https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API Geolocation API] at developer.mozilla.org


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


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


<script>
<html>
var x = document.getElementById("demo");
<p>Click the button to get your coordinates.</p>


function getLocation() {
<button onclick="getLocation()">Try It</button>
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else {
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}


function showPosition(position) {
<p id="ShowLatLonHere"></p>
  x.innerHTML = "Latitude: " + position.coords.latitude +
</html>
  "<br>Longitude: " + position.coords.longitude;
}
</script>
</pre>

Latest revision as of 16:51, 4 August 2022

Inspiration:


Click the button to get your coordinates.