android位置授权优化

feature/v-xuexi
wangdong 8 months ago
parent 4c766f5cf5
commit 467d9805e6
  1. 29
      pages/index/index.vue

@ -628,15 +628,9 @@ export default {
wx.setNavigationBarTitle({ wx.setNavigationBarTitle({
title:"一合知道" title:"一合知道"
}); });
if (!this.$util.getStorage('position')) { let platform = uni.getSystemInfoSync().platform;
getLocation(() => { if (platform !== 'android') {
this.$store.commit("app/" + SET_POSITION, '南京'); this.authPosition();
}).then(res => {
console.log(res);
this.getPositionAddress(res.lng, res.lat);
});
} else {
this.$store.commit("app/" + SET_POSITION, this.$util.getStorage('position'));
} }
this.getIndexData(); this.getIndexData();
this.getNewsList(); this.getNewsList();
@ -675,6 +669,18 @@ export default {
uni.setStorageSync('showWeixinLogin', 0); uni.setStorageSync('showWeixinLogin', 0);
} }
}, },
authPosition() {
if (!this.$util.getStorage('position')) {
getLocation(() => {
this.$store.commit("app/" + SET_POSITION, '南京');
}).then(res => {
console.log(res);
this.getPositionAddress(res.lng, res.lat);
});
} else {
this.$store.commit("app/" + SET_POSITION, this.$util.getStorage('position'));
}
},
getPositionAddress(longitude, latitude,) { getPositionAddress(longitude, latitude,) {
qqmapsdk.reverseGeocoder({ qqmapsdk.reverseGeocoder({
location: { location: {
@ -916,9 +922,14 @@ export default {
); );
}, },
toPosition() { toPosition() {
let platform = uni.getSystemInfoSync().platform;
if (platform === 'android' && !this.currentPosition) {
this.authPosition();
} else {
uni.navigateTo({ uni.navigateTo({
url: `/pages/index/position?position=${this.currentPosition}`, url: `/pages/index/position?position=${this.currentPosition}`,
}); });
}
}, },
}, },
}; };

Loading…
Cancel
Save