html5 geolocation为什么老是定位超时

qzxfl008 2013-06-28 04:26:42
环境:android4.0手机 chrome2.6,opera
手机连接的是4Gwifi终端wifi。使用chrome定位时始终是错误timeout,换opera浏览器,居然成功了,为什么使用chrome超时,而opera就能够定位成功,使用iphone上的chrome也能连接成功,连接的是同一个wifi,求大神指导

<!DOCTYPE html>
<html>
<body>
<p id="demo">get geolocation</p>
<button onclick="getLocation()" style="width: 100px;height: 50px">try</button>
<div id="mapholder"></div>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script>
var x=document.getElementById("demo");
var geolocationOptions={timeout:30000,enableHighAccuracy:true,maximumAge:5000};
var watchId;
var defalutX = 35.6196, defalultY = 139.7317;
function getLocation()
{
if (navigator.geolocation)
{
watchId = navigator.geolocation.watchPosition(showPosition, showError,geolocationOptions);
}
else{x.innerHTML="Geolocation is not supported by this browser.";}
}

function showPosition(position)
{
lat=position.coords.latitude;
lon=position.coords.longitude;
latlon=new google.maps.LatLng(lat, lon)
mapholder=document.getElementById('mapholder')
mapholder.style.height='250px';
mapholder.style.width='500px';

var myOptions={
center:latlon,zoom:14,
mapTypeId:google.maps.MapTypeId.ROADMAP,
mapTypeControl:false,
navigationControlOptions:{style:google.maps.NavigationControlStyle.SMALL}
};
var map=new google.maps.Map(document.getElementById("mapholder"),myOptions);
var marker=new google.maps.Marker({position:latlon,map:map,title:"You are here!"});
}
function showError(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED:
x.innerHTML="User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML="Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML="The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML="An unknown error occurred."
break;
}
}
</script>
</body>
</html>

...全文
401 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
原来缘来 2013-07-05
  • 打赏
  • 举报
回复
升级一下chrome试试 楼主是不是没有在Google play中下载的额?

39,082

社区成员

发帖
与我相关
我的任务
社区描述
HTML5是构建Web内容的一种语言描述方式。HTML5是互联网的下一代标准,是构建以及呈现互联网内容的一种语言方式.被认为是互联网的核心技术之一。
社区管理员
  • HTML5社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧