Safari 9中的地理位置始终返回“位置不可用" [英] Geolocation in Safari 9 always returning Position Unavailable

查看:69
本文介绍了Safari 9中的地理位置始终返回“位置不可用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个需要获取用户位置的应用程序.为此,我在按钮上附加了click事件,然后单击该事件

I'm building an app where I need to get the user's location. To do this I have a click event attached to a button, which then calls

navigator.geolocation.getCurrentPosition(getVenues, handleError);

这在Chrome和Firefox上可以正常工作,并且在我授予对我的位置的访问权后,会运行 getVenues 函数.在Safari上,授予访问权限后,立即调用 handleError 函数.

This works as expected on Chrome and Firefox, and the getVenues function is run after I grant access to my location. On Safari, after granting access the handleError function is immediately called.

这在我的本地和生产服务器上都发生,这两个服务器都使用HTTPS.我的电脑已建立wifi连接.Safari版本9.1.2(11601.7.7).我浏览了Safari中与Geolocation相关的其他一些帖子,到目前为止,没有一种解决方案有效.

This happens on both my local and production server, both of which use HTTPS. My computer is on a wifi connection. Safari Version 9.1.2 (11601.7.7). I have looked through some of the other posts related to Geolocation in Safari and none of the solutions have worked so far.

我尝试将选项传递给 getCurrentPosition 以增加 timeout maximumAge ,但是没有运气.

I have tried passing options to getCurrentPosition to increase the timeout and maximumAge but with no luck.

这是我的完整代码示例:

Here's my full code example:

$("#nearby-find").on('click', function() {
  navigator.geolocation.getCurrentPosition(getVenues, handleError);
});

var getVenues = function(position) {
  console.log(position);
};

var handleError = function(error) {
  console.log(error);
}

单击按钮会启动地理位置访问"请求,但是在单击接受"后立即调用 handleError 函数,错误代码为2(位置不可用).

Clicking the button initiates the Geolocation access request but immediately after clicking Accept the handleError function is called with an error code of 2 (Position Unavailable).

我需要检查的Safari地理位置是否还有其他问题/错误/陷阱?

Are there other issues/bugs/gotchas with Safari Geolocation I need to check?

推荐答案

在系统偏好设置"的启用位置服务"列表中,Safari不在应用程序列表中.您需要进入系统偏好设置>安全性和隐私>隐私标签,并确保Safari在启用位置服务"列表中.

Safari is not on the list of apps in the Enable Location Services list in System Preferences. You'll need to go into System Preferences > Security & Privacy > Privacy tab, and make sure Safari is on the Enable Location Services list.

这篇关于Safari 9中的地理位置始终返回“位置不可用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆