目录

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;
}
亲自试一试 »

描述

位置属性返回设备在地球上的位置和高度。

坐标属性

Property Description
position.coords Returns a Coordinates object that defines the current location
position.timestamp Returns a DOMTimeStamp representing the time at which the location was retrieved

浏览器支持

Property
position 5.0 9.0 3.5 5.0 16.0