【问题标题】:Client Location Detection Works on Safari Desktop But Not Safari Mobile客户端位置检测适用于 Safari 桌面,但不适用于 Safari 移动版
【发布时间】:2013-08-19 22:44:30
【问题描述】:

我正在尝试使用以下代码为我的移动网站设置客户端位置检测:

<html>
   <head>
   </head>
   <body>
      <script type="text/javascript" src="http://www.google.com/jsapi"></script>
      <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=geometry"></script>
      <script>
         var geocoder = new google.maps.Geocoder();
         var loc = {};
         if(google.loader.ClientLocation) {
         loc.lat = google.loader.ClientLocation.latitude;
         loc.lng = google.loader.ClientLocation.longitude;
         }
         var clientLocation = new google.maps.LatLng(loc.lat, loc.lng);
         alert(clientLocation);
      </script>
   </body>
</html>

当我在 Safari 移动浏览器上运行它时,通过返回 (NaN,NaN) 在我桌面上的 Safari 上运行良好。谁能建议可能出了什么问题?

【问题讨论】:

标签: javascript google-maps safari location mobile-safari


【解决方案1】:

我相信上面的代码有效。

我刚刚在我的 iPhone 5 上使用 Safari 进行了测试,它运行良好。

您确定在 iPhone 上为 Safari 启用了定位服务吗?确保您没有关闭它们。

【讨论】:

  • 嗯。事实证明我确实为 Safari 关闭了定位服务,但现在我已经打开它,清除了缓存,重新启动了我的 iphone 5,但我仍然得到 (NaN,NaN)。
  • 奇怪吧?我刷新了我的页面十几次......似乎每次都有效。我还尝试了我的移动 Chrome 浏览器。在那里也可以正常工作。我被难住了!
  • 出于好奇...如果您点击我的测试页面,它对您有用吗? charlessamet.com/test.html
  • 也许 ATT 的卫星需要一点时间才能找到我
猜你喜欢
  • 1970-01-01
  • 2014-01-15
  • 2013-11-22
  • 2015-09-02
  • 1970-01-01
  • 2015-10-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-06
相关资源
最近更新 更多