The HTML5 Geolocation

 The HTML5 Geolocation 


Geolocation API allows you to access the user's location information, with their permission, using JavaScript. You can use this information to display location-based content or to create location-aware web applications.


<button onclick="getLocation()">Get Location</button>


<script>

  function getLocation() {

    if (navigator.geolocation) {

      navigator.geolocation.getCurrentPosition(showPosition);

    } else {

      alert("Geolocation is not supported by this browser.");

    }

  }


  function showPosition(position) {

    alert(`Latitude: ${position.coords.latitude}, Longitude: ${position.coords.longitude}`);

  }

</script>

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...