Horje

Example of HTML Geolocation API

Try following Example
index.html
Example: HTML

<!DOCTYPE html>
<html>
 
<body>
    <p>Displaying location using Latitude and Longitude</p>
 
    <button class="geeks" onclick="getlocation()">
        Click Me
    </button>
    <p id="demo1"></p>
 
    <script>
        let variable1 = document.getElementById("demo1");
        function getlocation() {
            navigator.geolocation.getCurrentPosition(showLoc);
        }
        function showLoc(pos) {
            variable1.innerHTML =
                "Latitude: " +
                pos.coords.latitude +
                "<br>Longitude: " +
                pos.coords.longitude;
        }
    </script>
</body>
   
</html>





Type:
html
Category:
Web Tutorial
Sub Category:
HTML Geolocation API
Uploaded by:
Admin