点击获取位置按钮后执行下面的js
wx.getSetting({//获取用户已授权的信息
success(res) {
if (res.authSetting['scope.userLocation']==false){//如果没有授权地理位置
wx.openSetting({
success(res) {
res.authSetting = {//打开授权位置页面,让用户自己开启
"scope.userLocation": true
}
}
})
}else{//用户开启授权后可直接获取地理位置
wx.authorize({
scope: 'scope.userLocation',
success() {
//获取位置操作
}
})
}
}
})