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 属性返回设备在地球上的位置和高度。
Coordinates 属性
| 属性 | 描述 |
|---|---|
| position.coords | 返回定义当前位置的坐标对象 |
| position.timestamp | 返回表示获取到定位的时间的 DOMTimeStamp |
浏览器支持
| 属性 | |||||
|---|---|---|---|---|---|
| position | 5.0 | 9.0 | 3.5 | 5.0 | 16.0 |