uni.getLocation({
type: 'wgs84',
//geocode: true,
isHighAccuracy: true,
altitude: true,
highAccuracyExpireTime: '8000',
success: (res) => {
console.log("定位获取:", res);
//转换百度地图
// let x = longitude
// let y = latitude
// let x_pi = (3.14159265358979324 3000.0) / 180.0
// let z = Math.sqrt(x x + y y) + 0.00002 Math.sin(y x_pi)
// let theta = Math.atan2(y, x) + 0.000003 Math.cos(x x_pi)
// let lngs = z Math.cos(theta) + 0.0065
// let lats = z * Math.sin(theta) + 0.006
// lngs = Math.floor(lngs * 1000000) / 1000000;
// lats = Math.floor(lats * 1000000) / 1000000;
this.longitude = res.longitude;
this.latitude = res.latitude;
//this.poiName = res.address.poiName;
console.log('当前位置的经度:' + this.longitude);
console.log('当前位置的纬度:' + this.latitude);
uni.showToast({
title: "当前位置的经度:" + this.longitude +
"\r\n当前位置的纬度:" + this.latitude +
"\r\n当前地址位置:",
icon: 'none',
duration: 3000
})
},
fail: function(res) {
var titles = JSON.stringify(res);
uni.showToast({
title: titles,
icon: 'none',
duration: 3000
})
console.log(res)
console.log(JSON.stringify(res))
},
complete: function(res) {
console.log(JSON.stringify(res))
}
});
lzf李子凡 (作者)
用的就是高德地图
2023-07-31 08:48