Geolocation Error Handling

Example handling location errors.

Preview

Code

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

<p id="err"></p>

<script>
function getLoc(){
 navigator.geolocation.getCurrentPosition(
  function(pos){
   document.getElementById("err").innerText =
   pos.coords.latitude + ", " + pos.coords.longitude;
  },
  function(){
   document.getElementById("err").innerText =
   "Location access denied.";
  }
 );
}
</script>

More HTML Geolocation Examples (4)