Geolocation Error Handling
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>