使用 uni.onLocationChange获取地理位置后,仅在第一次进入该页面时执行,离开页面后下次进入该方法就不执行了
uni.startLocationUpdate({
type: 'gcj02',
success: res => {
console.log('开启应用接收位置消息成功', res)
this.locationUpdate = 'start'
let cb = (_res) => {
console.log('纬度:' + _res.latitude);
console.log('经度:' + _res.longitude);
if (!this.latitude || !this.longitude) {
this.latitude = _res.latitude
this.longitude = _res.longitude
}
}
uni.onLocationChange(cb);
uni.offLocationChange(cb);
},
fail: err => console.error('开启应用接收位置消息失败:', err),
complete: msg => console.log('调用开启应用接收位置消息 API 完成')
});
0 个回复