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