Geolocation in Safari 9 always returning Position Unavailable

荒凉一梦 提交于 2021-02-20 19:21:11

问题


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);

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.

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.

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);
}

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).

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


回答1:


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.



来源:https://stackoverflow.com/questions/39372870/geolocation-in-safari-9-always-returning-position-unavailable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!