HTML & JavaScript Geo Location test: Difference between revisions
(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: | ||
<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> | ||
</pre> |
Revision as of 17: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>