From 170c089715ffce00225d35416d30f60bafdee157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=89?= <814457906@qq.com> Date: Thu, 4 Jan 2024 09:00:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/register/register.vue | 33 +++++++++++++++++++++++++++++++++ pages/startup/startup.vue | 6 +++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/pages/register/register.vue b/pages/register/register.vue index b9d709e..65e3b25 100644 --- a/pages/register/register.vue +++ b/pages/register/register.vue @@ -341,6 +341,38 @@ // uni.$off('code'); // }, 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']), // 与户主关系 nationSelect(e) { @@ -526,6 +558,7 @@ }, //进入界面加载 onLoad(options) { + this.getAddress() let that = this // console.log(options, '00') uni.$on('headPictureUrl', (res) => { diff --git a/pages/startup/startup.vue b/pages/startup/startup.vue index 2421e28..3a5f360 100644 --- a/pages/startup/startup.vue +++ b/pages/startup/startup.vue @@ -42,9 +42,9 @@ }, onShow() { var that = this - if (!uni.getStorageSync('location') && !uni.getStorageSync('region')) { - this.getAddress() - } + // if (!uni.getStorageSync('location') && !uni.getStorageSync('region')) { + // this.getAddress() + // } // this.getAddress(); createMobileToken().then(res => { uni.setStorageSync("token", res.data.token)