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   }
    */

 

錯誤代碼:git

  • Permission denied - 用戶不容許地理定位
  • Position unavailable - 沒法獲取當前位置
  • Timeout - 操做超時

 

coords.latitude 十進制數的緯度
coords.longitude 十進制數的經度
coords.accuracy 位置精度
coords.altitude 海拔,海平面以上以米計
coords.altitudeAccuracy 位置的海拔精度
coords.heading 方向,從正北開始以度計
coords.speed 速度,以米/每秒計
timestamp 響應的日期/時間
相關文章
相關標籤/搜索