在vue文件的onready中使用位置监听,返回的经纬度有时候是gcj02坐标系,有时候是wgs84坐标系。在公园山上的时候定位无法定位只实时位置,
上传附件zip为实地测试录屏,uniapp开发的和高德地图之间的对比,高德可以跟着移动,uniapp只能定位到山下且不再移动
onReady(){
let _this = this;
uni.startLocationUpdate({
success: ress => {
console.log('开启小程序接收位置消息成功');
uni.onLocationChange(function (res) {
console.log(res);
if(o_x != res.longitude && o_y != res.latitude){
// console.log("o_x", o_x);
let userinfo = uni.getStorageSync("userinfo");
let humanid = JSON.parse(userinfo).HUMANID
let humanname = JSON.parse(userinfo).HUMANNAME
// console.log(humanid + ' 纬度:' + res.latitude +' 经度:' + res.longitude);
o_x = res.longitude;
o_y = res.latitude;
_this.wv.evalJS(`updateLocation(${res.longitude},${res.latitude})`)
_this.$run(`insert into ymfz.tbtrace(uuid,humanid,HUMANname,x,y,createtime,loctype) values('${nanoid(32)}',${humanid},'${humanname}',${res.longitude},${res.latitude},now(),0);`).then(res=>{
// console.log(res);
})
}
});
},
fail: err => console.error('开启小程序接收位置消息失败:', err),
complete: msg => console.log('调用开启小程序接收位置消息 API 完成')
});
}