in News
javascript get current location latitude and longitude
The getCurrentPosition() method is used to return the user’s position. <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> Example explained: Check if Geolocation is supported If supported, run the getCurrentPosition() method. If not, […]
You must be logged in to post a comment.