Basic Geolocation

Example retrieving the user location.

Preview

Code

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

<p id="geo"></p>

<script>
function getLocation(){
 if(navigator.geolocation){
  navigator.geolocation.getCurrentPosition(function(pos){
   document.getElementById("geo").innerText =
   pos.coords.latitude + ", " + pos.coords.longitude;
  });
 }
}
</script>

More HTML Geolocation Examples (4)