export const isGetLocation = () => { // #ifdef MP-ALIPAY return new Promise((resolve, reject) => { const systemSetting = my.getSystemSetting(); if (!systemSetting.locationEnabled) { my.showModal({ title: '提示', content: '需要获取您的位置信息,请前往设置页面开启位置权限', success(modalRes) { if (modalRes.confirm) { my.showAuthGuide({ authType: 'LBS', success() { const systemSetting = my.getSystemSetting(); if (systemSetting.locationEnabled) { // 用户在引导页面开启了位置权限,调用my.getLocation获取位置信息 resolve(true); } else { // 用户依然未开启位置权限 resolve(false); } }, fail() { // 引导页面调用失败,可能用户取消了操作 resolve(false); } }); } else { // 用户点击取消 resolve(false); } } }); } else { console.log("系统已授权"); my.getSetting({ success(settingRes) { console.log("小程序授权了吗"); console.log(settingRes); if (!settingRes.authSetting['location']) { // 用户未授权位置权限,引导用户去设置页面开启权限 uni.showModal({ title: '提示', content: '需要获取您的位置信息,请前往设置页面开启位置权限', success(modalRes) { if (modalRes.confirm) { uni.openSetting({ success(openSettingRes) { if (openSettingRes.authSetting['location']) { // 用户在设置页面开启了位置权限,调用uni.getLocation获取位置信息 resolve(true); } else { // 用户依然未开启位置权限 resolve(false); } } }); } else { // 用户点击取消 resolve(false); } } }); } else { // 用户已授权,调用my.getLocation获取位置信息 resolve(true); } }, fail(err) { reject(err); } }); } }); // #endif // #ifdef MP-WEIXIN return new Promise((resolve, reject) => { uni.getSetting({ success(settingRes) { console.clear(settingRes); console.log(settingRes); if (!settingRes.authSetting['scope.userLocation']) { // 用户未授权位置权限,引导用户去设置页面开启权限 uni.showModal({ title: '提示', content: '需要获取您的位置信息,请前往设置页面开启位置权限', success(modalRes) { if (modalRes.confirm) { uni.openSetting({ success(openSettingRes) { if (openSettingRes.authSetting['scope.userLocation']) { // 用户在设置页面开启了位置权限,调用uni.getLocation获取位置信息 resolve(true); } else { // 用户依然未开启位置权限 resolve(false); } } }); } else { // 用户点击取消 resolve(false); } } }); } else { // 用户已授权,调用uni.getLocation获取位置信息 resolve(true); } }, fail(err) { reject(err); } }); }); // #endif }