zoukankan      html  css  js  c++  java
  • webapp网络定位

     1 <script>
     2 var x=document.getElementById("demo");
     3 function getLocation()
     4   {
     5   if (navigator.geolocation)
     6     {
     7     navigator.geolocation.getCurrentPosition(showPosition);
     8     }
     9   else{x.innerHTML="Geolocation is not supported by this browser.";}
    10   }
    11 function showPosition(position)
    12   {
    13   x.innerHTML="Latitude: " + position.coords.latitude +
    14   "<br />Longitude: " + position.coords.longitude;
    15   }
    16 </script>
    17 /*
    18 function showError(error)
    19   {
    20   switch(error.code)
    21     {
    22     case error.PERMISSION_DENIED:
    23       x.innerHTML="User denied the request for Geolocation."
    24       break;
    25     case error.POSITION_UNAVAILABLE:
    26       x.innerHTML="Location information is unavailable."
    27       break;
    28     case error.TIMEOUT:
    29       x.innerHTML="The request to get user location timed out."
    30       break;
    31     case error.UNKNOWN_ERROR:
    32       x.innerHTML="An unknown error occurred."
    33       break;
    34     }
    35   }
        */

    错误代码:

    • Permission denied - 用户不允许地理定位
    • Position unavailable - 无法获取当前位置
    • Timeout - 操作超时
    coords.latitude 十进制数的纬度
    coords.longitude 十进制数的经度
    coords.accuracy 位置精度
    coords.altitude 海拔,海平面以上以米计
    coords.altitudeAccuracy 位置的海拔精度
    coords.heading 方向,从正北开始以度计
    coords.speed 速度,以米/每秒计
    timestamp 响应的日期/时间
  • 相关阅读:
    Cypress自动化框架笔记
    SSH 用公钥免密登录,需要改文件权限
    python函数的可变参数 *和**
    Socket进程处理被中断的系统调用及Accept函数返回EINTR错误处理 (转)
    perror 与 strerror
    perror 函数
    strerror 函数
    getch ()函数 (来自百度百科)
    C语言运算符及其优先级汇总表口诀
    第四章
  • 原文地址:https://www.cnblogs.com/vichang/p/9596432.html
Copyright © 2011-2022 走看看