遇到的问题:调用wx.onLocationChange接口获取实时定位,使用华为navo12pro 手机,获取实时经纬度数据时每隔2秒收到一次消息,经纬度数据需要经过10秒到20秒才会更新一次,消息中的speed值一直为0。使用其他设备时每隔1秒收到一次消息,经纬度数据都是实时更新的,speed值也是一直变化的。
手机已开启精准定位,微信小程序已设置使用小程序时和离开后允许获取位置信息。
小程序基础库使用的是3.6.2
调用方法如下:
this.getWXLocationPermission()
.then(res => {
// 先取消之前的定位监听,再重新开启
this.offLocationChange()
wx.onLocationChange(this.locationChangeFn)
this.closeErrLocation()
})
.catch(err => {
// console.log("start location error", err)
this.allEvent('开启定位监听失败', +new Date())
this.openErrLocation()
})
// 监听实时地理位置变化事件 的 函数
locationChangeFn(res) {
var isStart = this.data?.isStart;
var isNeedCamera = this.data?.isNeedCamera;
var markers = this.data?.markers;
var type = this.data?.type;
var time = this.data?.time;
var firstImgSrc = this.data?.firstImgSrc;
var latitude = res.latitude;
var longitude = res.longitude;
var speed = res.speed;
}
获取的实时经纬度数据如下:

speed这个是非必须的, 和系统厂商都有关系
返回经纬度数据快的设备1s,慢的2s