HTML5地理定位实例

发布时间:2022-04-13 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了HTML5地理定位实例脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了htML5获取地理定位的方法,分享给大家供大家参考。具体方法如下:

html5 获取坐标代码如下:


复制代码
代码如下:
<!DOCTYPE HTML>
<html>
<head>
<tITle>test1.html</title>

<;meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<div id="demo">点击这个按钮,获得您的坐标:</div>
<button onclick="getLocation()">试一下</button>
<script type="text/javascript">

VAR x=document.getElementById("demo");
function getLocation(){
if(navigator.geolocation){
navigator.geolocation.getcurrentPosition(showPosition);
}else{
x.innerHTML="浏览器不支持!!!";
}
}
function showPosition(position){
x.innerHTML="Latitude: "+position.coords.latitude+"<br/>Longitude: "+position.coords.longitude;
}
</script>

</body>
</html>

经测试,在IE9 、firefox、chrome、opera上都可以成功获取到坐标位置,但是safari 5.x上却不能返回坐标,暂时木有找到原因。成功的案例里头,chrome响应的速度最快,其次是opera,然后是IE9,firefox居然是最慢的。个人表示对firefox很失望,不过chrome倒是越来棒了。

希望本文所述对大家的HTML5程序设计有所帮助。

脚本宝典总结

以上是脚本宝典为你收集整理的HTML5地理定位实例全部内容,希望文章能够帮你解决HTML5地理定位实例所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。