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>
    
  • 相关阅读:
    thymeleaf 模板引擎
    thymeleaf 内联语法
    thymeleaf 局部变量、属性优先级、注释
    PYNQ上手笔记 | ① 启动Pynq
    MSP430F5529时钟系统深究
    C#上位机开发(四)—— SerialAssistant功能完善
    C#上位机开发(三)—— 构建SerialAssistant雏形
    C#上位机开发(二)—— Hello,World
    C#上位机开发(一)—— 了解上位机
    FPGA学习笔记(八)—— 状态机设计实例之独立按键消抖
  • 原文地址:https://www.cnblogs.com/bravolove/p/5991851.html
Copyright © 2011-2022 走看看