HTML5地理位置 - 错误回调并不总是触发

时间:2012-11-19 23:45:14

标签: javascript html5 geolocation

我正以这种相当简单的方式使用Geolocation API:

if (navigator && navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position){
        console.log("gettingPosition: " + position);
        myFunction(position(;
    }, function(error){
        console.log('did not get position');
        console.log(error);
    });     

}

在某些情况下(Firefox 12.0是我面前的浏览器)如果用户单击“Not Now”,则不会触发回调,甚至不会出现错误。这是预期的吗?如果是这样,我唯一的选择是遵循Geolocation feedback while accepting the request中的技术并设置我自己的超时?

1 个答案:

答案 0 :(得分:1)

这似乎是设计的(适用于Firefox)。请参阅Josh在https://bugzilla.mozilla.org/show_bug.cgi?id=635175

中的评论

逻辑是单击“不是现在”是用户解除权限对话框的一种方式,而不会决定是否允许地理定位权限。

看起来FF16和Chrome-Latest都以这种方式运行。

(P.S。不要射击信使。:p)