k***@163.com
k***@163.com
  • 发布:2025-06-19 10:18
  • 更新:2025-06-19 10:18
  • 阅读:21

使用 uni.onLocationChange获取地理位置后,仅在第一次进入该页面时执行,离开页面后下次进入就不执行了

分类:uni-app x

使用 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 完成')  
                });
2025-06-19 10:18 负责人:无 分享
已邀请:

要回复问题请先登录注册