js文件
// 获取位置信息
getUserLocation() {
const _this = this
wx.getSetting({
success(res) {
console.log(res.authSetting)
if (res.authSetting['scope.userLocation']) {
//授权了
_this.setData({
not_auth: false
})
wx.getLocation({
type: 'wgs84',
success(res) {
_this.setData({
latitude: res.latitude,
longitude: res.longitude
})
},
fail(res) {
_this.setData({
not_auth: true
})
wx.showToast({
title: '请先开启手机定位功能',
icon: 'none',
duration: 3000
})
}
})
} else {
//没有授权
_this.setData({
not_auth: true
})
wx.openSetting({
success(res) {
console.log(res.authSetting)
}
})
}
},
fail(res) {}
})
},