wx.getLocation({
type: 'wgs84',
isHighAccuracy: true,
success: (res) => {
console.log('微信小程序定位', res)
const baseUrl = decodeURIComponent(wx.getStorageSync("baseUrl"));
const token = wx.getStorageSync("token");
const authHeader = wx.getStorageSync("authHeader");
let longitude = 0, latitude = 0;
if (this.data.positionArr.length < 5) {
this.data.positionArr.push([res.longitude, res.latitude])
}
if (this.data.positionArr.length == 5) {
this.data.positionArr.forEach((item) => {
console.log(item, 'this.data.positionArr.item')
longitude += item[0];
latitude += item[1];
})
longitude = longitude / 5;
latitude = latitude / 5;
this.data.positionArr = [];
}
console.log(longitude, latitude, 'longitude')
if (!longitude || !latitude) return
console.log('更新位置', longitude, latitude)
});
},
fail: (err) => {
}
});
目前采用定时器一秒调用一次微信定位的api,五秒五个点,取平均数当作一个点,相对好了一些,但是感觉不太够用,有没有更好的办法?