zoukankan      html  css  js  c++  java
  • js

     1.单次请求

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <input type="button" value="请求位置信息"><br>
    <textarea name="content" id="content" cols="30" rows="10"></textarea>
    <script>
        window.onload = function () {
            var oBtn = document.getElementsByTagName('input')[0];
            var oTextarea = document.getElementById('content');
    
            oBtn.onclick = function () {
                navigator.geolocation.getCurrentPosition(function (position) {
                    oTextarea.value += "
     当前经度:"+position.coords.longitude;
                    oTextarea.value += "
     当前纬度:"+position.coords.latitude;
                    oTextarea.value += '
     准确度:' + position.coords.accuracy;
                    oTextarea.value += '
     海拔:' + position.coords.altitude;
                    oTextarea.value +='
     海拔准确度:'+ position.coords.altitudeAccuracy;
                    oTextarea.value += '
     行进方向:' + position.coords.heading;
                }, function (error) {
                    alert(error.code);
                },{
                    enableHighAcuracy : true,
                    timeout :10000,
                    maximumAge : 10000
                });
            }
        }
    </script>
    
    </body>
    </html>
    

     2.连续请求

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <input type="button" value="请求位置信息"><br>
    <textarea name="content" id="content" cols="30" rows="10"></textarea>
    <script>
        window.onload = function () {
            var oBtn = document.getElementsByTagName('input')[0];
            var oTextarea = document.getElementById('content');
            var timer = null;
    
            timer = oBtn.onclick = function () {
                navigator.geolocation.watchPosition(function (position) { //多次连续请求地址
                    oTextarea.value += "
     当前经度:"+position.coords.longitude;
                    oTextarea.value += "
     当前纬度:"+position.coords.latitude;
                    oTextarea.value += '
     准确度:' + position.coords.accuracy;
                    oTextarea.value += '
     海拔:' + position.coords.altitude;
                    oTextarea.value +='
     海拔准确度:'+ position.coords.altitudeAccuracy;
                    oTextarea.value += '
     行进方向:' + position.coords.heading;
                }, function (error) {
                    alert(error.code);
                    navigator.geolocation.clearWatch(timer);//关闭连续请求
                },{
                    enableHighAcuracy : true,
                    timeout :10000,
                    maximumAge : 10000
                });
            }
        }
    </script>
    
    </body>
    </html>
    
  • 相关阅读:
    软测试-计算机组成原理、系统和网络安全机构
    POJ 2044 Weather Forecast
    Cocos2d-x 3.x 头像选择,本地相册图片+图片编辑(Android、IOS双平台)
    Spring-----1、Spring一个简短的引论
    捕android程序崩溃日志
    java 正则表达式例子, 查找字符串
    java中Pattern.compile函数的相关解释
    java JdbcTemplate源码
    eclipse 常用快捷键整理
    java 正则表达式去除标点符号
  • 原文地址:https://www.cnblogs.com/bravolove/p/5991851.html
Copyright © 2011-2022 走看看