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 响应的日期/时间
posted @ 2018-09-06 09:31  vichang  阅读(301)  评论(0编辑  收藏  举报