// 加载当前定位
getLocation() {
let that = this
qqmapsdk.reverseGeocoder({
// 获取你当前的位置
success: function (res) {
let city = res.result.address_component.city
console.log(city, res);
that.setData({
cityName: city,
localSuccess: true
})
},
fail: (err) => {
console.log(err)
// 当status==1000时,说明没有成功获取到当前定位
if (err.status == 1000) {
//提示用户 定位失败
this.setData({
cityname: "定位失败,点击重试"
})
// 弹出窗口,引导定位
this.showAuthDialog()
}
}
});
},
// 弹出定位权限授权引导窗口
showAuthDialog() {
// 模态对话框
wx.showModal({
title: "授权提示",
content: "无法获取定位权限,是否重新授权",
success: (res) => {
if (res.confirm) {
//点了确定
// 跳转到Setting页面
wx.openSetting({
// 返回用户设置的操作结果
success: (settingRes) => {
console.log(settingRes)
if(settingRes.authSetting['scope.userLocation']){
this.getLocation()//已经获取权限,重新定位
}
}
})
}
}
})
},