最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Geolocation Current Position API not working in IE11.5 windows10 - Stack Overflow

programmeradmin1浏览0评论

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

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

Share Improve this question edited Apr 6, 2017 at 6:23 Novice asked Apr 4, 2017 at 11:51 NoviceNovice 4781 gold badge6 silver badges22 bronze badges 1
  • I've got the same problem. I'm running IE Version 11.447.14393.0 – neumann1990 Commented Apr 12, 2017 at 18:26
Add a ment  | 

2 Answers 2

Reset to default 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./en-us/library/gg593067(v=vs.85).aspx

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

发布评论

评论列表(0)

  1. 暂无评论