1.提示用户打开手机系统定位
let system = uni.getSystemInfoSync(); // 获取系统信息
// 手机系统定位
if (!system.locationEnabled) {
uni.showModal({
title: '提示',
content: '手机系统定位未打开!',
showCancel: false,
success: function(res) {
if (res.confirm) {
console.log('用户点击确定');
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
return;
}
2.小程序定位授权
//定位授权
uni.getSetting({
success(res) {
if (!res.authSetting['scope.userLocation']) {
// 未授权或未打开定位
uni.showModal({
title: '提示',
content: '请打开定位并授权给小程序!',
showCancel: false,
success: function(res) {
if (res.confirm) {
console.log('用户点击确定');
// 引导用户去设置打开权限
uni.openSetting();
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
return;
}
}
});