调用方法即可
getLoction() {
let that = this;
wx.getSetting({
success(res) {
console.log('222222',res)
if (res.authSetting['scope.userFuzzyLocation']===false) {
wx.showModal({
title: '请授权位置信息',
success(res) {
wx.openSetting({
success(openSettingres) {
console.log('ccccc', openSettingres.authSetting)
if (openSettingres.authSetting["scope.userFuzzyLocation"] == true) {
wx.getFuzzyLocation({
type: 'wgs84',
success(getFuzres) {
console.log('getFuzzyLocation-res', getFuzres)
const latitude = getFuzres.latitude
const longitude = getFuzres.longitude
that.setData({
loc_lat_long: latitude + ',' + longitude
})
},
fail(err) {
console.log('getFuzzyLocation-err', err)
that.getLoction()
}
})
} else {
that.getLoction()
}
},
fail(err) {
console.log('openSetting-err', err)
}
})
}
})
} else {
console.log('3333333')
wx.getFuzzyLocation({
type: 'wgs84',
success(getFuzres) {
console.log('getFuzzyLocation-res', getFuzres)
const latitude = getFuzres.latitude
const longitude = getFuzres.longitude
that.setData({
loc_lat_long: latitude + ',' + longitude
})
},
fail(err) {
console.log('getFuzzyLocation-err', err)
that.getLoction()
}
})
}
}
})
},