小程序获取微信内部地址,微信有提供api,但是获取内部地址需要获得用户授权,首次拒绝授权的情况下,第二次要通过openSetting来打开授权页面进行授权
getWxAddress () { wx.getSetting({ success: (res)=>{ if (res.authSetting['scope.address'] == false) { wx.openSetting({ success: (res)=>{ this.chooseWxAddress() }, fail: ()=>{ console.log('拒绝授权') } }) } else { wx.authorize({ scope: 'scope.address', success: (result)=>{ this.chooseWxAddress() }, fail: ()=>{ console.log('拒绝授权') } }); } }, fail: ()=>{} }) }, chooseWxAddress () { wx.chooseAddress({ success: (res)=>{ let addrObj = { province: res.provinceName, city: res.cityName, district: res.countyName, address: res.detailInfo } this.setData({ addrObj }) }, fail: ()=>{ console.log('取消选择地址') } }) },