I want to do tasks after the user makes no decision on the location’s permission. I have tried the following:
navigator.geolocation.getCurrentPosition((pos) => {
let lat = pos.coords.latitude;
let long = pos.coords.longitude;
console.log(lat, long);
console.log("User granted permission");
}, (error) => {
console.error(error);
console.error("User didn't grant permission");
}, {
timeout: 3000,
maximumAge: 3000,
enableHighAccuracy: true
});
I have set timeout
and maximumAge
attributes to 3000
ms, but it didn’t work anymore. The error will only be triggered if the user closes the permission pop-up. How can I detect if the user makes no decision after 3 seconds? Thank you.
2
Answers
You can add setTimeout call before getCurrentPosition and clear timeoutID if the user does something:
With some code updates you can achieve it, like thus way