This commit is contained in:
2024-01-04 09:00:39 +08:00
parent cc7dade9d7
commit 170c089715
2 changed files with 36 additions and 3 deletions

View File

@ -341,6 +341,38 @@
// uni.$off('code'); // uni.$off('code');
// }, // },
methods: { methods: {
//
getAddress() {
let that = this;
uni.getLocation({
type: 'wgs84',
success: (res) => {
let location = res.latitude + ',' + res.longitude
//
uni.request({
url: 'https://apis.map.qq.com/ws/geocoder/v1/?location=location', //
data: {
location: location,
'key': "Q4DBZ-UIMC2-B63UX-CUZ6A-S3UT7-TBF3V", //Key
},
method: "GET",
success(res) {
uni.setStorageSync('location', res.data.result.address_component.city)
},
fail: res => {
console.log(res.errMsg, '解析失败返回的错误信息');
}
})
},
//
fail: (res) => {
uni.showToast({
icon: 'none',
title: '获取地址失败,请打开定位',
})
}
})
},
...mapMutations(['scoket']), ...mapMutations(['scoket']),
// //
nationSelect(e) { nationSelect(e) {
@ -526,6 +558,7 @@
}, },
// //
onLoad(options) { onLoad(options) {
this.getAddress()
let that = this let that = this
// console.log(options, '00') // console.log(options, '00')
uni.$on('headPictureUrl', (res) => { uni.$on('headPictureUrl', (res) => {

View File

@ -42,9 +42,9 @@
}, },
onShow() { onShow() {
var that = this var that = this
if (!uni.getStorageSync('location') && !uni.getStorageSync('region')) { // if (!uni.getStorageSync('location') && !uni.getStorageSync('region')) {
this.getAddress() // this.getAddress()
} // }
// this.getAddress(); // this.getAddress();
createMobileToken().then(res => { createMobileToken().then(res => {
uni.setStorageSync("token", res.data.token) uni.setStorageSync("token", res.data.token)