HTML & JavaScript Geo Location test: Difference between revisions

From munkjensen.net/wiki
mNo edit summary
mNo edit summary
Line 1: Line 1:
'''Inspiration:'''  
'''Inspiration:'''  
* https://www.mediawiki.org/wiki/Adding_JavaScript_to_Wiki_Pages
* https://www.mediawiki.org/wiki/Adding_JavaScript_to_Wiki_Pages
<pre>
<html>
<p>Click the button to get your coordinates.</p>
<p>Click the button to get your coordinates.</p>


Line 7: Line 7:


<p id="demo"></p>
<p id="demo"></p>
 
</html>
<pre>
<script>
<script>
var x = document.getElementById("demo");
var x = document.getElementById("demo");

Revision as of 15:40, 4 August 2022

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>