【问题标题】:navigator.geolocation.getCurrentPosition in chrome extensionchrome 扩展中的 navigator.geolocation.getCurrentPosition
【发布时间】:2012-09-16 06:10:05
【问题描述】:

我正在尝试在 chrome 扩展中使用以下功能:

    function findMe(){
    if( navigator.geolocation ){
        navigator.geolocation.getCurrentPosition(alert("YES"), alert("NO"));
    }
}

我收到“NO”警报,getCurrentPosition 不起作用,如何解决?

【问题讨论】:

标签: javascript google-chrome-extension geolocation


【解决方案1】:

getCurrentPosition() 接受 2 个参数,它们必须是函数。所以你应该将函数作为参数传递。

工作代码:

navigator.geolocation.getCurrentPosition(function(position) {
    console.log(position);
}, function(positionError) {
    console.error(positionError);
});

另请参阅:http://diveintohtml5.info/geolocation.html

【讨论】:

  • 顺便说一句,有一个 chrome 权限“地理位置”,它会在不征求用户许可的情况下返回用户的地理位置。
猜你喜欢
  • 1970-01-01
  • 2015-11-26
  • 1970-01-01
  • 2011-06-30
  • 2017-10-15
  • 2016-04-09
  • 2016-04-20
  • 1970-01-01
相关资源
最近更新 更多