六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 106|回复: 0

HTML5 学习之地理定位

[复制链接]

升级  14.67%

18

主题

18

主题

18

主题

秀才

Rank: 2

积分
72
 楼主| 发表于 2013-1-29 13:39:31 | 显示全部楼层 |阅读模式
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 >试一下</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倒是越来棒了。
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表