头闻号

岳阳市岳阳楼区环球环保化工服务部

净水絮凝剂|脱水剂|活性炭|其他空气处理化学品|氢氧化钠|其他水处理化学品

首页 > 新闻中心 > 科技常识:HTML5地理定位实例
科技常识:HTML5地理定位实例
发布时间:2023-02-01 10:08:04        浏览次数:5        返回列表

今天小编跟大家讲解下有关HTML5地理定位实例 ,相信小伙伴们对这个话题应该有所关注吧,小编也收集到了有关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="https://www.aidi.net.cn//html5/./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程序设计有所帮助。

来源:爱蒂网