// 獲取當前地地址 async getLocation() { let self = this let result = null try { const resultLocation = await wepy.getLocation() result = await this.geocoder(resultLocation) } catch (e) { wx.getSetting({ success: function (res) { console.log('getSetting...', res) let statu = res.authSetting if (!statu['scope.userLocation']) { wx.showModal({ title: '是否授權當前位置', content: '需要獲取您的地理位置,請確認授權,否則將無法獲得優惠券', success: function (tip) { if (tip.confirm) { wx.openSetting({ success: function (data) { console.log('openSetting...', data) if (data.authSetting['scope.userLocation'] === true) { wepy.showToast({ title: '授權成功', icon: 'success', duration: 1000 }) // 授權成功之后,再調用chooseLocation選擇地方 wepy.getLocation({ success(res) { self.geocoder(res) } }) } else { // 開關關閉,提示無法拿到位置權限 wx.showModal({ title: '提示', content: '無法使用定位權限', confirmText: '太遺憾了', showCancel: false }) } }, fail: function(res) { console.log('openSetting.failed' + res) } }) } if (tip.cancel) { wx.showToast({ title: '定位失敗', icon: 'none', duration: 1000 }) } } }) } else { wepy.showModal({ title: '定位服務已關閉', content: '請在“設置”中打開定位服務,以便精准定位獲取更多優惠消息!' }) } }, fail: function (res) { console.log(res) wepy.showToast({ title: '調用授權窗口失敗', icon: 'success', duration: 1000 }) } }) } return result }
