Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Geolocation Current Position API not working in IE11.5 windows10

Geolocation current position API is inconsistent in IE11 windows 10 machine. Below is the code

 function setCurrentPos(event, firstLoad) {
                navigator.geolocation.getCurrentPosition(function (position) {
                    firstLoad || setCurrentLocation(event.target, position.coords);
                }, function (error) {
                    1 === error.code && ($this.currentLocDenied = !0);
                });
            }

4 out of 5 times it is falling into the error block with response code 2(POSITION_UNAVAILABLE) stating "The current position could not be determined.".

The browser prompt that appears to allow user to access location is set to allow so that should not be the reason.

Version Info

enter image description here Any other suggestions??

like image 523
Novice Avatar asked Oct 30 '22 09:10

Novice


1 Answers

Fixed

1 – Changes that I described below should be added only for IE. So please check if the browser is IE if we need to add a workaround. Do not change the others browser.

2 – Change the accuracy of enableHighAccuracy to false. I know that is false by default but just in case.

3 – Add some reasonable value on the maximumAge for the cache time. (Just for IE)

var locationOptions = {};
if(deviceInfo.raw.browser.isIE && parseInt(deviceInfo.browser_version) == 11 &&  deviceInfo.os.isWindows10) {
            locationOptions = {
                enableHighAccuracy: false,
                  maximumAge: 50000
            }
    }

function setCurrentPos(event, firstLoad) {
                navigator.geolocation.getCurrentPosition(function (position) {
                    //success callback
                }, function (error) {
                        //error callback
                }, locationOptions);
            }

Reference - https://msdn.microsoft.com/en-us/library/gg593067(v=vs.85).aspx

like image 85
Novice Avatar answered Nov 15 '22 04:11

Novice