How to use geolocation ? | Sololearn: Learn to code for FREE!

+4

How to use geolocation ?

10/27/2016 1:47:44 PM

Jaydeep Khatri

1 Answer

New Answer

+1

<!DOCTYPE html> <body> <p id="position" onload="getLocation()">position</p> </body> </html> <script> var x = document.getElementById("position"); 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>