Geolocation: Using HTML Geolocation

Using HTML Geolocation

//the example below returns the latitude and longitude of 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>

The getCurrentPosition() method is used to return the user's position.

Related concepts

Geolocation: Using HTML Geolocation — Structure map

Clickable & Draggable!

Geolocation: Using HTML Geolocation — Related pages: