HTML & JavaScript Geo Location test

From munkjensen.net/wiki
Revision as of 17:40, 31 July 2022 by Admin (talk | contribs) (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 +...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

[NOWIKI]

Click the button to get your coordinates.

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

<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 + 
 "
Longitude: " + position.coords.longitude;

} </script> [/NOWIKI]