由于小程序更新,在微信客户端7.0.0及以上版本需要使用精准定位的时候,需要再app.json里面加上permission属性之后才能调用scope.userLocation地址授权信息,先用getSetting检查是否授权,未授权authorize发起授权,已授权直接chooseLocation拉取定位,若是已禁止授权,则用类型为openSetting的button让客户打开授权页面,开启授权,因为禁止授权之后无法二次授权,所以只能用button让客户手动刷新授权状态
// 地图
lookaddress(e) {
var that=this;
wx.getSetting({
success: function (res) {
// console.log(res)
if (!res.authSetting['scope.userLocation']) {
if (res.authSetting['scope.userLocation'] === false) {
that.setData({
'scope': true
})
wx.showModal({
title: '温馨提示',
content: '若需要获取定位信息,请开启定位权限',
showCancel: false
})
}
if (res.authSetting['scope.userLocation'] === true) {
that.setData({
'scope': false
})
}
wx.authorize({
scope: 'scope.userLocation',
success: function (res) {
wx.chooseLocation({
success: function (res1) {
console.log('aedrhbuifuil',res1)
},
})
}
})
} else {
wx.chooseLocation({
success: function (res1) {
console.log(res1)
},
})
}
}
})
},