我正在使用 navigator.geolocation
对象中的 getCurrentPosition
函数。当用户选择共享本地化或从不共享时,我没有问题,但是当用户选择“这次不”时,我无法输入功能错误。这是我的代码:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, getLocationIp);
} else {
console.log ( "Geolocation is not supported by this browser.");
}
};
function showPosition(position) {
console.log( "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude);
cargarArticulosInicio(position.coords.latitude,position.coords.longitude);
}
function getLocationIp() {
//function get location from ip
}
最佳答案
不幸的是,这是 Firefox 浏览器团队的决定:
Bug 675533 - Share location- "Not Now" Doesn't fire error callback
This is by design. Not Now hides the popup but allows you to make a decision at a later time, therefore it invokes no callbacks. Never Share will trigger the error callback.
理由是,如果用户选择“现在不”,则应解释为“我现在不想选择”,因此就好像他/她从未回答过问题一样。
至少直到他/她重新打开弹出问题并选择另一个选项(共享、始终共享或从不共享,后一种情况是唯一调用错误回调的情况)。
当然,在这种情况下如果能有一个调用回调的选项就好了。提到的错误页面中很多人都在要求它。
目前唯一的解决方法是使用超时。
关于javascript - 地理定位功能错误不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34616383/