You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
2.0 KiB
50 lines
2.0 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
<title>调用手机原生定位功能</title>
|
|
</head>
|
|
|
|
<body>
|
|
<button οnclick="getGeocode()">获取定位</button>
|
|
<div id='text'></div>
|
|
</body>
|
|
<script>
|
|
function geoInf(position) {
|
|
var str = "";
|
|
str += "地址:" + position.addresses + "\n";//获取地址信息
|
|
str += "这是定位地市:" + position.address.city + "\n";
|
|
str += "坐标类型:" + position.coordsType + "\n";
|
|
var timeflag = position.timestamp;//获取到地理位置信息的时间戳;一个毫秒数;
|
|
str += "时间戳:" + timeflag + "\n";
|
|
var codns = position.coords;//获取地理坐标信息;
|
|
var lat = codns.latitude;//获取到当前位置的纬度;
|
|
str += "纬度:" + lat + "\n";
|
|
var longt = codns.longitude;//获取到当前位置的经度
|
|
str += "经度:" + longt + "\n";
|
|
var alt = codns.altitude;//获取到当前位置的海拔信息;
|
|
str += "海拔:" + alt + "\n";
|
|
var accu = codns.accuracy;//地理坐标信息精确度信息;
|
|
str += "精确度:" + accu + "\n";
|
|
var altAcc = codns.altitudeAccuracy;//获取海拔信息的精确度;
|
|
str += "海拔精确度:" + altAcc + "\n";
|
|
var head = codns.heading;//获取设备的移动方向;
|
|
str += "移动方向:" + head + "\n";
|
|
var sped = codns.speed;//获取设备的移动速度;
|
|
str += "移动速度:" + sped;
|
|
console.log(JSON.stringify(position));
|
|
document.getElementById("text").innerHTML = str;
|
|
}
|
|
// 通过定位模块获取位置信息
|
|
function getGeocode() {
|
|
plus.geolocation.getCurrentPosition(geoInf, function (e) {
|
|
alert("获取定位位置信息失败:" + e.message);
|
|
}, { geocode: true });
|
|
}
|
|
|
|
</script>
|
|
|
|
</html>
|