本文实例讲述了ht ML 5获取地理定位的方法,分享给大家供大家参考。具体方法如下:
html5 获取坐标代码如下:
复制代码
代码如下:<!DOCTY PE HTML>
<html>
<head>
<t IT le> test1 .html</title>
< ;m eta http-equiv="keywo rds " content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content -t ype" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" hr ef="./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.get current Position(showPosition);
}else{
x.innerHTML="浏览器不支持!!!";
}
}
function showPosition(position){
x.innerHTML="Latitude: "+position.coords.latitude+"< br />Longitude: "+position.coords.longitude;
}
</script>
</body>
</html>
经测试,在IE9 、firefox、ch rom e、 opera 上都可以成功获取到坐标位置,但是safari 5.x上却不能返回坐标,暂时木有找到 原因 。成功的案例里头,chrome响应的速度最快,其次是opera,然后是IE9,firefox居然是最慢的。个人表示对firefox很失望, 不过 chrome倒是越来棒了。
希望本文所述对大家的HTML5 程序设计 有所帮助。
总结
以上是 为你收集整理的 HTML5地理定位实例 全部内容,希望文章能够帮你解决 HTML5地理定位实例 所遇到的问题。
如果觉得 网站内容还不错, 推荐好友。