Geolocation position 屬性
- 上一頁 getCurrentPosition()
- 下一頁 coordinates
- 返回上一層 Geolocation 對象
定義和用法
position 屬性返回設備在地球上的位置和高度。
實例
獲取用戶所在位置的經緯度:
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; }
position 屬性
屬性 | 描述 |
---|---|
position.coords | 返回定義當前位置的 Coordinates 對象。 |
position.timestamp | 返回 DOMTimeStamp 對象,表示位置被檢索的時間。 |
瀏覽器支持
屬性 | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
position | 5.0 | 9.0 | 3.5 | 5.0 | 16.0 |
- 上一頁 getCurrentPosition()
- 下一頁 coordinates
- 返回上一層 Geolocation 對象