【发布时间】: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 上运行良好。谁能建议可能出了什么问题?
【问题讨论】:
-
我猜你的桌面和你的 iPhone 没有共享相同的 IP 吗? ClientLocation 是基于 IP 的,不保证可以解析任何 IP。看看stackoverflow.com/questions/14195837/…
标签: javascript google-maps safari location mobile-safari