author () {
const that =this
uni.authorize({
scope: 'scope.userLocation',
success(){ //1.1 允许授权
uni.getLocation({
type: 'gcj02', //返回可以用于uni.openLocation的经纬度
success: function (res) {
that.latitude = res.latitude;
that.longitude = res.longitude;
that.sub()
}
})
},
fail(){ //1.2 拒绝授权
uni.showModal({
content:'检测到您没打开获取信息功能权限,是否去设置打开?',
confirmText: "确认",
cancelText:'取消',
success: (res) => {
if(res.confirm){
uni.openSetting({
success: (res) => {
console.log(res);
that.getLocation();
}
})
}else{
console.log('取消');
return false;
}
}
})
return false;
}
})
},
getLocation(){
uni.getLocation({
type: 'gcj02', //返回可以用于uni.openLocation的经纬度
success: function (res) {
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
this.latitude = res.latitude;
this.longitude = res.longitude;
}
});
},