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)