Nov*_*ice 5 javascript internet-explorer-11 windows-10 google-location-services
Geolocation 当前位置 API 在 IE11 windows 10 机器中不一致。下面是代码
function setCurrentPos(event, firstLoad) {
navigator.geolocation.getCurrentPosition(function (position) {
firstLoad || setCurrentLocation(event.target, position.coords);
}, function (error) {
1 === error.code && ($this.currentLocDenied = !0);
});
}
Run Code Online (Sandbox Code Playgroud)
5 次中有 4 次掉入错误块,响应代码为 2(POSITION_UNAVAILABLE),说明“无法确定当前位置。”。
出现允许用户访问位置的浏览器提示设置为允许,因此这不应成为原因。
版本信息
固定的
\n\n1 \xe2\x80\x93 我在下面描述的更改应该仅针对 IE 添加。因此,如果我们需要添加解决方法,请检查浏览器是否为 IE。不要更改其他浏览器。
\n\n2 \xe2\x80\x93 将enableHighAccuracy 的精度更改为false。我知道默认情况下这是错误的,但以防万一。
\n\n3 \xe2\x80\x93 为缓存时间的maximumAge 添加一些合理的值。(仅适用于IE)
\n\nvar locationOptions = {};\nif(deviceInfo.raw.browser.isIE && parseInt(deviceInfo.browser_version) == 11 && deviceInfo.os.isWindows10) {\n locationOptions = {\n enableHighAccuracy: false,\n maximumAge: 50000\n }\n }\n\nfunction setCurrentPos(event, firstLoad) {\n navigator.geolocation.getCurrentPosition(function (position) {\n //success callback\n }, function (error) {\n //error callback\n }, locationOptions);\n }\nRun Code Online (Sandbox Code Playgroud)\n\n参考 - https://msdn.microsoft.com/en-us/library/gg593067(v=vs.85).aspx
\n| 归档时间: |
|
| 查看次数: |
5325 次 |
| 最近记录: |