网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 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倒是越来棒了。
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/15 11:20:23