<script>
function getLocation()
{
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(showPosition,showError);
}
else{alert('该浏览器不支持获取地理位置。');}
}
function showPosition(position)
{
alert("当前经度: " + position.coords.longitude +
"<br />当前纬度: " + position.coords.latitude);
}
function showError(error){
switch(error.code)
{
case error.PERMISSION_DENIED:
alert('位置服务被拒绝');
break;
case error.POSITION_UNAVAILABLE:
alert('地址信息不合法');
break;
case error.TIMEOUT:
alert('请求超时');
break;
case error.UNKNOWN_ERROR:
alert('不知名错误');
break;
}
}
getLocation();
</script>
获取地理位置
最新推荐文章于 2023-08-18 14:35:04 发布