5

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??

Novice
  • 458
  • 1
  • 6
  • 21

2 Answers2

2

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

Novice
  • 458
  • 1
  • 6
  • 21
  • This didn't work for me, Let me know what I went wrong with. – Vinayak Infotech Jun 26 '20 at 13:29
  • $("#btn").click(function(){ var options1 = { enableHighAccuracy: false, maximumAge: 60000 }; setCurrentPos(options1); }); function setCurrentPos(options1) { navigator.geolocation.getCurrentPosition(function (position) { alert("success"); }, function (error) { alert("error"); }, options1); } – Vinayak Infotech Jun 26 '20 at 13:30
0

Until today (4.4.2017) "navigator.geolocation.getCurrentPosition" works perfect under win10 insider preview 15063.11 + IE11,Edge,FF. BUT today only timeout error is occurs. So something big is happening right now in the network

*Updated: on 5.4.2017 all works fine again

Angel T
  • 182
  • 2
  • 7
  • Just updated the correct version of IE is it that IE 11.5 has some issues with geoLocation API – Novice Apr 06 '17 at 06:24
  • I am using IE11.0.15063.0. for now geolocation works as expected – Angel T Apr 06 '17 at 06:52
  • Itried running the W3 school geolocation demo on my IE 11.5 https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation_error This is also showing the same behavior it works once and then gives error code as 2. If possible try running the same on IE 11.5 on your windows 10 machine – Novice Apr 06 '17 at 07:29