• 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>
    
  • 相关阅读:
    Speech_recognition
    Unity3D
    Kinect
    matlab
    debian install
    menu.lst
    RStudio
    System.BadImageFormatException
    C语言期末复习划重点啦!赶上复习的末班车,祝你期末考试不挂科!
    程序员的中年危机:不是物质的匮乏,而是身份的焦虑
  • 原文地址:https://www.cnblogs.com/bravolove/p/5991851.html
Copyright © 2020-2023  润新知