HTML5 GEOLocation 2nd prompt

Is there a way to call the user again for geolocation on some kind of trigger after they have refused to share places?

navigator.geolocation.getCurrentPosition 

runs it once, successive calls do not give the same result. I can not find the answer anywhere /

+7
source share
2 answers

Take a look at this code snippet and this SO Answer: What is the best jQuery plugin that handles HTML5 location?

 if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(successFunction, errorFunction); }else{ errorFunction(); } function successFunction(position) { //uses HTML5 if available var lat = position.coords.latitude; var lng = position.coords.longitude; } function errorFunction(){ //uses IP if no HTML5 $.getJSON("http://freegeoip.net/json/", function(res){ var lat = res.latitude; var lng = res.longitude; }); } 

Take a look at this Fiddle Link also JQuery Geolocator Plugin

0
source

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) { /* CALL EXTERNAL API HERE */ console.warn('ERROR(' + err.code + '): ' + err.message); }; navigator.geolocation.getCurrentPosition(success, error, options); 
0
source

All Articles