客户端位置检测在Safari桌面上有效,但在Safari手机上无效

Client Location Detection Works on Safari Desktop But Not Safari Mobile

本文关键字:Safari 但在 无效 手机 有效 桌面 位置 检测 客户端      更新时间:2023-09-26

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

<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上运行得很好。有人能提出可能出了什么问题吗?

我相信上面的代码是有效的。

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

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

相关文章: