Geolocation position 属性
- 前のページ getCurrentPosition()
- 次のページ coordinates
- 上一层に戻る Geolocation オブジェクト
定義と使用法
position 属性は、デバイスが地球に位置する場所と高さを返します。
例
ユーザーの位置の経度と緯度を取得します:
var x = document.getElementById("demo"); function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else { x.innerHTML = "このブラウザでは geolocation がサポートされていません."; } } function showPosition(position) { x.innerHTML = "緯度: " + position.coords.latitude + "<br>経度: " + 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 オブジェクト