wx.getLocation()位置不能及时更新
- 当前 Bug 的表现(可附上截图)
本人拿着手机一直在移动,但是小程序中的经纬度却不能及时更新,几分钟还没有变化。
我开发了一个类似功能安卓app,经纬度都能及时更新,且精度较高。
本人去年完成这个功能的时候,测试效果还是不错,在楼顶移动时,精度可达3米。
- 预期表现
能及时更新位置信息,精度能与app一样,
- 复现路径
可以直接在本人的小程序复现,我用的华为P10和P20手机都不能及时更新位置信息。
- 提供一个最简复现 Demo
这是获取位置信息的方法
updateLocation: function() { var that = this; wx.getLocation({ type: "wgs84",//gps定位 altitude: true, success: function(res) { that.setData({ lat: res.latitude, lon: res.longitude, accuracy: res.accuracy, speed: Math.round(res.speed * 3.6) > 0 ? Math.round(res.speed * 3.6) : 0 }) console.log(res.latitude+"--"+res.longitude+"--"+res.speed) }, complete:function(res) { console.log(res) } }); }, |
这是每秒更新一次位置信息的方法
openGPS: function(e) { isLocation = e.detail.value; if (isLocation) { //实时更新位置信息 updateInterval = setInterval(this.updateLocation, 1000); } else { clearInterval(updateInterval); clearInterval(autoPlayInterval); } }, |
