Reputation: 18103
navigator.geolocation.getCurrentPosition(
function(pos) {
var fullpos = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
computePartners(fullpos);
}
);
is what I have. It executes computePartners() if the client has allowed access for knowing where he is (getting clients physical position). But if it has not, I would like to make output an alert('Error'), example. How can i do this?
Upvotes: 0
Views: 1002
Reputation: 1774
I use this code for geolocation:
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
// ok
}, function(error) {
if(error.code == 0){
// unknown error
} else if(error.code == 1) {
// permission denied
} else if(error.code == 2) {
// position unavailable
} else if(error.code == 3) {
// timeout
}
console.log(error.message);
}, {
enableHighAccuracy: true,
maximumAge: 30000,
timeout: 10000
});
} else {
// browser do not support geolocation
}
Upvotes: 3