JS 8
//we can deconstruct the position argument to get the COORDinateS
navigator.geolocation.getCurrentPosition( async ( {coords: {latitude, longitude}}) =>{
console.log("We are at lat " + latitude + " and lon " + longitude)
}, showError
);
/we can add a callback function for all the possible errors
function showError(error) {
if(error){
switch(error.code) {
case error.PERMISSION_DENIED:
user.innerHTML = "User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
user.innerHTML = "Location information is unavailable."
break;
case error.TIMEOUT:
user.innerHTML = "The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
user.innerHTML = "An unknown error occurred."
break;
}
}
}
Designing maps with MapBox

Last updated