HTML & JavaScript Geo Location test: Difference between revisions
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> | <pre> | ||
<p>Click the button to get your coordinates.</p> | <p>Click the button to get your coordinates.</p> |
Revision as of 15:37, 4 August 2022
Inspiration:
<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>