Browse Source

修复页面加载时无法显示正确地址信息的问题

pull/1/head
SwTt29 2 months ago
parent
commit
745e0078e6
  1. 23
      pages/profile/index.js

23
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('开始加载用户信息')

Loading…
Cancel
Save