【发布时间】:2019-05-23 03:48:24
【问题描述】:
【问题讨论】:
-
你看过这个吗?可能会有所帮助。 stackoverflow.com/questions/6092400/…
标签: javascript jquery internet-explorer geolocation confirmation
【问题讨论】:
标签: javascript jquery internet-explorer geolocation confirmation
下面的脚本在页面加载时启动,并要求用户使用他们的位置。我只是从documentation example 中添加了一小段代码来检查错误代码 - 错误代码 1 表示权限被拒绝..
权限被拒绝的原因有多种,例如在代码 sn-ps 中返回错误代码 1,但由于 Stack Overflow 通过策略拒绝地理定位功能,类似地在 JSFiddle 上。
您可以改用错误消息,它看起来更准确。不同浏览器的错误信息略有不同:
您可以改为对错误消息使用以下检查,而不是代码:
if ( err.message == "User denied Geolocation" || err.message == "User denied geolocation prompt" ) {
// Your code goes here
}
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
console.log('Your current position is:');
console.log(`Latitude : ${crd.latitude}`);
console.log(`Longitude: ${crd.longitude}`);
console.log(`More or less ${crd.accuracy} meters.`);
}
function error(err) {
// Check for permission denied error
if (err.code == 1) {
alert("Permission denied to use location");
// Add your code here
}
console.warn(`ERROR(${err.code}): ${err.message}`);
}
navigator.geolocation.getCurrentPosition(success, error, options);
【讨论】:
【讨论】:
我们再次确认 IE 不支持捕获此事件,对于由此造成的不便,我们深表歉意。 同时,不确定以下解决方法是否可以帮助您。 使用“a = navigator.geolocation.getCurrentPosition(success);” 代替 “navigator.geolocation.getCurrentPosition(成功,错误,选项);”然后手动检查 a 是否为空值,如果为空,则表示客户尚未准备好共享该位置。你可以吗?
谢谢
【讨论】: