diff --git a/pages/profile/index.js b/pages/profile/index.js index 8ec9eae..ce4b0d8 100644 --- a/pages/profile/index.js +++ b/pages/profile/index.js @@ -11,11 +11,13 @@ Page({ onLoad() { this.loadUserInfo(); + this.loadLocationInfo(); this.checkLocationAuth(); }, onShow() { this.loadUserInfo(); + this.loadLocationInfo(); this.checkLocationAuth(); // 更新自定义tabBar状态 if (typeof this.getTabBar === 'function' && this.getTabBar()) { @@ -28,6 +30,27 @@ Page({ app.updateCurrentTab('profile'); }, + // 加载位置信息 + loadLocationInfo() { + // 首先从本地存储获取保存的地址信息 + const savedAddress = wx.getStorageSync('locationInfo'); + if (savedAddress) { + this.setData({ locationInfo: savedAddress }); + console.log('从本地存储加载地址信息:', savedAddress); + return; + } + + // 如果本地没有,检查是否有经纬度信息可以进行逆地理编码 + const savedLocation = wx.getStorageSync('userLocation'); + if (savedLocation && savedLocation.latitude && savedLocation.longitude) { + console.log('从本地存储加载经纬度信息:', savedLocation); + this.reverseGeocode(savedLocation.latitude, savedLocation.longitude); + return; + } + + console.log('没有保存的位置信息'); + }, + // 加载用户信息 loadUserInfo() { console.log('开始加载用户信息')