目的
注意
chooseLocation() {
let that = this
wx.chooseLocation({
latitude: '',
longitude: '',
success(res) {
console.log(res)
that.setData({
'query.dz': res.address,
'query.x': res.longitude,
'query.y': res.latitude
})
},
fail(res) {
console.log(res)
wx.getSetting({
success: function(res) {
var statu = res.authSetting
if (!statu['scope.userLocation']) {
wx.showModal({
title: '是否授权当前位置',
content: '需要获取您的地理位置,请确认授权,否则选择位置功能将无法使用',
success: function(tip) {
if (tip.confirm) {
wx.openSetting({
success: function(data) {
if (data.authSetting['scope.userLocation'] === true) {
wx.showToast({
title: '授权成功',
icon: 'success',
duration: 1000
})
//授权成功之后,再调用chooseLocation选择地方
wx.chooseLocation({
success(res) {
console.log(res)
that.setData({
'query.dz': res.address,
'query.x': res.longitude,
'query.y': res.latitude
})
}
})
} else {
wx.showToast({
title: '授权失败',
icon: 'error',
duration: 1000
})
}
}
})
}
}
})
}
},
fail: function(res) {
wx.showToast({
title: '调用授权窗口失败',
icon: 'error',
duration: 1000
})
}
})
}
})
}