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

1
  • I've got the same problem. I'm running IE Version 11.447.14393.0 Apr 12, 2017 at 18:26

2 Answers 2

3

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

2
  • This didn't work for me, Let me know what I went wrong with. Jun 26, 2020 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); } Jun 26, 2020 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

3
  • Just updated the correct version of IE is it that IE 11.5 has some issues with geoLocation API
    – Novice
    Apr 6, 2017 at 6:24
  • I am using IE11.0.15063.0. for now geolocation works as expected
    – Angel T
    Apr 6, 2017 at 6:52
  • Itried running the W3 school geolocation demo on my IE 11.5 w3schools.com/html/… 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 6, 2017 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.