how i use geolocation function | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

how i use geolocation function

someone give me complete code to ise geolocation function.

27th Oct 2016, 6:52 AM
Muhammad Osman
Muhammad Osman - avatar
1 Answer
+ 6
Copied from http://www.w3schools.com/html/html5_geolocation.asp: <!DOCTYPE html> <html> <body> <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> </body> </html>
27th Oct 2016, 12:11 PM
Sean Medlin
Sean Medlin - avatar