0

我尝试使用地理定位,它适用于我所有的浏览器,除了 safari。

这是我正在运行的脚本。

if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function (location) {
        console.log('success');
    }, function () {
        console.log('error');
    });
} else {
    console.log('denied');
}

我也为此创建了一个小提琴

我在 windows 7 pro 上运行 safari 5.1.7。有什么我做错了吗?

谢谢!

4

2 回答 2

1

I don't have an answer. Just want to add a little "me too" with some little fragments.

This is very peculiar. I've had no trouble with this feature for years, wired, wifi, whatever.

Now it has just started failing (Mac Snow Leopard, Safari 5.1.10). Link to fiddle fails, google's example fails, my own code which has been working fine for years also fails. Sometimes it's error code 2, sometimes just a timeout. (I am using timeout of 60000 - one minute).

Works fine on other browsers. Also no problem with iOS Safari connected to the exact same wireless network.

于 2013-10-16T09:00:04.037 回答
0

不,你的代码是正确的

实际上,所有浏览器都会获得地理位置,但如果您使用有线连接,则只有 Safari 浏览器无法获得地理位置,但如果您使用的是 wifi,那么它将起作用。

我不知道为什么这个问题只发生在 safari 浏览器中。我有同样的问题,如果有人找到替代方式,我会尝试其他方式来获取地理位置,然后请在堆栈溢出时发布。

于 2014-04-11T13:18:01.677 回答