Geolocation coordinates 屬性
- 上一頁 coordinates
- 下一頁 getCurrentPosition()
- 返回上一層 Geolocation 對象
定義和用法
coordinates 屬性返回設備在地球上的位置和高度。
實例
獲取用戶所在位置的經緯度:
var x = document.getElementById("demo"); function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else { x.innerHTML = "Geolocation is not supported by this browser."; } } function showPosition(position) { x.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude; }
Coordinates 屬性
屬性 | 描述 |
---|---|
coordinates.latitude | 返回位置的緯度,以十進制度數計。 |
coordinates.longitude | 返回位置的經度,以十進制度數計。 |
coordinates.altitude | 返回位置的高度,相對于海平面,以米計。 |
coordinates.accuracy | 返回 latitude 和 longitude 屬性的精度,以米計。 |
coordinates.altitudeAccuracy | 返回 altitude 屬性的精度,以米計。 |
coordinates.heading | 返回設備行進的方向。該值以度數計,表示設備與正北方向相差多遠。 0 度代表正北,方向為順時針方向(東為 90 度,西為 270 度)。如果速度為 0,則 heading 為 NaN。如果設備無法提供航向信息,則該值為 null。 |
coordinates.speed | 返回設備的速度,以米/秒為單位。該值可以為 null。 |
瀏覽器支持
屬性 | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
coordinates | 5.0 | 9.0 | 3.5 | 5.0 | 10.6 |
- 上一頁 coordinates
- 下一頁 getCurrentPosition()
- 返回上一層 Geolocation 對象