uniapp H5端 使用 uni.onLocationChange 只在初始化更新了一次就不再更新位置信息。
uni.startLocationUpdate({
success: res => {
uni.onLocationChange(function(res) {
_this.latitude = res.latitude;
_this.longitude = res.longitude;
_this.center[0] = res.longitude;
_this.center[1] = res.latitude;
console.log('纬度:' + res.latitude);
console.log('经度:' + res.longitude);
});
},
fail: err => console.error('开启小程序接收位置消息失败:', err),
complete: msg => console.log('调用开启小程序接收位置消息 API 完成')
});
DCloud_UNI_WZF
设备移动一段距离是否更新
2023-05-06 17:13
啷个 (作者)
回复 DCloud_UNI_WZF: 移动可能数十米才会更新,但是如果关闭屏幕再打开就立即更新了
2023-05-06 17:25
DCloud_UNI_WZF
回复 啷个: navigator.geolocation.watchPosition 能力如此,如果需要更精细的控制,可能需要看看地图服务商是否有对应服务或者自己做心跳检测
2023-05-06 18:27