In the geolocation API? Not.
If the user clicks "Deny permission", it simply means "No, and do not bother me again ..."
However, the user can do this by deleting the Place-Share settings, and, of course, the prompt will pop up again.
Or the user can simply change the settings if the browser allows it, however, for example, Chrome manages these settings as exceptions (regardless of whether the userβs permission is allowed or not), so the user needs to delete the settings, respectively. exception in any case.
Now what?
Your only option is to catch the error and use, for example. some external API to find the user's location by IP. You can program it yourself or, of course, the existing solutions offered by @Venkat.
But remember that IP geolocation is a difficult task - sometimes it has the accuracy of the number of addresses, sometimes it is just the accuracy of the state.
This example from Mozilla docs shows a good example of handling geolocation errors:
var options = { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 }; function success(pos) { var crd = pos.coords; console.log('Your current position is:'); console.log('Latitude : ' + crd.latitude); console.log('Longitude: ' + crd.longitude); console.log('More or less ' + crd.accuracy + ' meters.'); }; function error(err) { console.warn('ERROR(' + err.code + '): ' + err.message); }; navigator.geolocation.getCurrentPosition(success, error, options);
jave.web
source share