// 开启定时
startTimer() {
this.timer = setInterval(() => {
// 调用获取位置的方法传递坐标
this.getWeizhi();
}, 10000)
},
// 清除定时器
stopTimer() {
clearInterval(this.timer);
},
// 获取位置信息传递坐标
getWeizhi() {
let that = this;
uni.getLocation({
type: 'gcj02',
geocode: true,
isHighAccuracy: false,
success: function(zuobiao) {
// console.log(res, '位置信息')
// console.log('当前位置的经度:' + res.longitude);
// console.log('当前位置的纬度:' + res.latitude);
let location = {
longitude: zuobiao.longitude,
latitude: zuobiao.latitude,
}
uni.setStorage({
key: 'location',
data: location,
});
// uni.setStorageSync('location', location);
//存储下当前位置的地名
let addressName = '';
addressName = (zuobiao.address.province != undefined ? zuobiao.address.province : '') +
(zuobiao
.address.city != undefined ? zuobiao.address.city : '') + (zuobiao.address
.district !=
undefined ? zuobiao.address.district : '') + (zuobiao.address.street !=
undefined ? zuobiao
.address.street : '') + (zuobiao.address.streetNum != undefined ? zuobiao
.address
.streetNum : '') + (zuobiao.address.poiName != undefined ? zuobiao.address
.poiName :
'');
// console.log(addressName, '城市名字')
uni.setStorage({
key: 'addressName',
data: addressName,
});
// uni.setStorageSync('addressName', addressName);
// console.log(uni.getStorageSync('coords'))
let data = {
latitude: zuobiao.latitude,
longitude: zuobiao.longitude
}
// put_coords(data).then(reslut => {
// // console.log(reslut)
// })
let token = uni.getStorageSync('token')
uni.request({
url: that.$config.gateway,
method: 'POST',
data: data,
header: {
'content-type': 'application/json',
},
success: (reslut) => {
console.log('请求成功')
// 停止定时任务
that.stopTimer();
// 开启定时任务
that.startTimer();
// console.log(reslut)
}
})
}
});
},
2 个回复
x***@163.com (作者)
请教下大佬们这是怎么回事
7***@qq.com
1、开启高精定位isHighAccuracy
2、定位本来就没呢么准