客户端位置检测在Safari桌面上有效,但在Safari手机上无效
Client Location Detection Works on Safari Desktop But Not Safari Mobile
我正在尝试使用以下代码为我的移动网站设置客户端位置检测:
<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启用了定位服务吗?确保您没有关闭它们。
相关文章:
- JavaScript函数在Safari中有效,但在Firefox中找不到
- 这个jQuery代码在Mozilla上运行良好,但在Chrome,Opera,Safari上则不然
- 在Rails中使用remote:true在Chrome中有效,但在Safari中无效——从js.erb文件调用succe
- 在getJSON之后构建HTML在Safari中有效,但在Chrome或Firefox中无效
- Date对象在Chrome中有效,但在Safari、Firefox或IE中无效
- 为什么这个html5音频不能在chrome上工作,但在safari上工作得很好
- Cordova iframe在iOS Safari中工作,但在Android中不起作用
- Ipad:window.height() 在 Safari 中给出不好的值,但在 Chrome 中没有
- Element 没有显示在 FireFox 和 Opera 上,但在 Chrome 和 Safari 上可以正常工作
- IF 在 Chrome 中返回 true,但在 Safari 中返回 false
大小属性在 Safari 中受支持,但在 JS img 对象中缺失
- Javascript函数在IE中工作,但在FF,Chrome或Mobile Safari中不起作用
- Ajax 调用在 chrome/safari 中工作,但在 ff 和 ie 中失败
- 音频元素在Safari中运行良好,但在XCode模拟器(web视图)中中断
- 客户端位置检测在Safari桌面上有效,但在Safari手机上无效
- 画布图像行为在Safari中正常,但在其他浏览器中则不然
- 功能在IE8中运行良好,但在Chrome、Mozilla、safari中则不然
- 文件阅读器API在Safari中无法正常工作,但在chrome中工作正常
- 约会数学在Chrome上有效,但在Firefox或Safari上无效
- jQuery'滚动前删除锚点'功能不能在firefox中工作,但在chrome、safari中可以完美工