Geolocation Current Position API not working in IE11.5 windows10

浪尽此生 提交于 2021-01-27 07:50:39

问题


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

Any other suggestions??


回答1:


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:


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



来源:https://stackoverflow.com/questions/43206442/geolocation-current-position-api-not-working-in-ie11-5-windows10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!