Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
44
rated 0 times [  46] [ 2]  / answers: 1 / hits: 28849  / 7 Years ago, mon, february 27, 2017, 12:00:00

How can I prompt a user for their geo-location in javascript if they've blocked my request in the past? (using navigator.geolocation.getCurrentPosition).



For example, my web app requires location services, and the user accidentally clicks block, or they change their mind. What can I do to prompt them again?


More From » html

 Answers
1

As mentioned by @matthew-shwery, you can not change the permission.

the best you could do is check for the permission and notify the user is the permission is denied



navigator.permissions.query({
name: 'geolocation'
}).then(function(result) {
if (result.state == 'granted') {
report(result.state);
geoBtn.style.display = 'none';
} else if (result.state == 'prompt') {
report(result.state);
geoBtn.style.display = 'none';

navigator.geolocation.getCurrentPosition(revealPosition, positionDenied, geoSettings);
} else if (result.state == 'denied') {
report(result.state);
geoBtn.style.display = 'inline';
}
result.onchange = function() {
report(result.state);
}
});


Geolocation docs


[#58765] Friday, February 24, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
micayla

Total Points: 148
Total Questions: 92
Total Answers: 109

Location: Aruba
Member since Sat, Oct 2, 2021
3 Years ago
micayla questions
Fri, Dec 24, 21, 00:00, 2 Years ago
Thu, Apr 16, 20, 00:00, 4 Years ago
Thu, Nov 14, 19, 00:00, 5 Years ago
;