javascript - 地理定位功能错误不起作用

标签 javascript geolocation

我正在使用 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/

相关文章:

javascript - 在 chrome 中选择单击时更新选项

Javascript 解构器

android - 哪些设备支持 Android 传感器批处理?

javascript - 获取所有业务推荐字段

javascript - OfflineAudioContext.startRendering() 基于 promise 的函数在 safari 中不起作用

python - 始终允许使用 Selenium 在 Firefox 中进行地理定位

android - 如何让 Android 用户在 Google map 上搜索我创建的最近的兴趣点?

geolocation - 如何在不使用 API 的情况下查找 IP 地址的位置?

cordova - GPS 定位(开/关)事件

javascript - 如何使用 mocha.js 模拟用于单元测试的依赖类?