获取用户位置的纬度和经度:
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;
}
亲自试一试 »
getCurrentPosition() 方法返回设备的当前位置。
Method | |||||
---|---|---|---|---|---|
getCurrentPosition() | 5.0 | 9.0 | 3.5 | 5.0 | 16.0 |
navigator.geolocation.getCurrentPosition(
success, error, options)
Parameter | Type | Description |
---|---|---|
success | Required. A callback function that takes a Position object as its sole input parameter | |
error | Optional. A callback function that takes a PositionError object as its sole input parameter | |
options | Optional. A PositionOptions object |
设备的当前位置 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!