Firefox无法找到位置,但Safari无法找到

时间:2011-02-12 20:06:22

标签: javascript jquery safari geolocation

我正在尝试让我的代码在Mac上使用Safari(可以在iOS设备上运行,甚至可以在iPhone模拟器中运行......)。在Firefox中,它可以正常工作,但在Safari中却没有:

  if ($('.latitude-field').length && navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(pos) {
      var lat = pos.coords.latitude;
      var lon = pos.coords.longitude;

      $('.latitude-field').val(lat);
      $('.longitude-field').val(lon);

      $('.geolocation-status').text('Location: ' + lat + ', ' + lon);
    }, function(err) {
      $('.geolocation-status').text('Unable to find location.' + err.message);
    });
  }

我做错了什么?

1 个答案:

答案 0 :(得分:0)

您是否已选中“系统偏好设置”面板和Safari?两者都有一个安全项目,其中有一个选项允许或不允许获取位置。