地理位置当前位置API在IE11.5 Windows10中不起作用 [英] Geolocation Current Position API not working in IE11.5 windows10

查看:64
本文介绍了地理位置当前位置API在IE11.5 Windows10中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Geolocation当前位置API在IE11 Windows 10机器中不一致.下面是代码

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);
                });
            }

5次中有4次掉入错误块,响应代码2(POSITION_UNAVAILABLE)指出无法确定当前位置."

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.

版本信息

还有其他建议吗?

推荐答案

固定

1 –我下面描述的更改应仅针对IE添加.因此,如果需要添加解决方法,请检查浏览器是否为IE.请勿更改其他浏览器.

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 –将enableHighAccuracy的精度更改为false.我知道默认情况下这是错误的,但以防万一.

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

3 –为缓存时间在maximumAge上添加一些合理的值.(仅适用于IE)

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);
            }

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

这篇关于地理位置当前位置API在IE11.5 Windows10中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆