问题背景
近期有用户反馈陀螺匠 APP 考勤打卡功能存在定位不精确、导致部分用户无法正常完成打卡,影响考勤数据准确性。
修复范围
- 涉及文件:
\pages\attendance\index.vue - 修复代码行:第 354 行的getLocation 方法(考勤打卡核心定位逻辑)
修复后核心逻辑
const getLocation = () => {
if (!isLocationEnable.value) return;
const updateLocationInfo = (res) => {
nowXy.value = {
longitude: res.longitude,
latitude: res.latitude
}
let distance = getDistance(nowXy.value, rangeXy.value)
if (distance <= effectiveRange.value) {
isLocationRange.value = true
} else {
isLocationRange.value = false
}
turnAdrr(nowXy.value.longitude, nowXy.value.latitude)
}
// #ifdef WEB
if (window.plus) {
let isGetLocationSuccess = false;
const providers = ["amap", "baidu"];
let failCount = 0;
const processResult = (res) => {
if (!isGetLocationSuccess && res && res.latitude && res.longitude) {
isGetLocationSuccess = true;
updateLocationInfo(res);
}
}
providers.forEach((provider, index) => {
plus.geolocation.getCurrentPosition(r => {
if (r.coords) {
processResult(r.coords);
} else {
failCount++;
if (!isGetLocationSuccess && failCount >= providers.length) {
console.log("获取位置信息失败");
}
}
}, e => {
failCount++;
if (!isGetLocationSuccess && failCount >= providers.length) {
console.log("获取位置信息失败");
}
}, { provider });
});
return;
}
// #endif
uni.getLocation({
type: 'gcj02',
isHighAccuracy: true,
success: (res) => {
updateLocationInfo(res);
},
fail: (err) => {
if (err.errMsg === 'getLocation:fail Geolocation permission denied') {
console.log('用户拒绝了位置权限请求')
uni.showToast({
title: '用户拒绝了位置权限请求',
icon: 'none',
})
} else {
console.log('获取位置信息失败:', err.errMsg)
uni.showToast({
title: '获取位置信息失败',
icon: 'none',
})
}
},
})
}
修复效果
- 移动端:定位精度提升,权限提示更精准,用户可清晰知晓定位失败原因;
- 整体:考勤打卡时定位异常、超出打卡范围误判等问题得到解决,打卡流程更稳定。
注意事项
- 直接找到对应文件代码位置,复制粘贴上面的代码。
- 前端代码修改完后需要重新打包更新
H5打包更新: https://doc.crmeb.com/tuoluojiang/tuoluojiang22/31914
APP打包更新: https://doc.crmeb.com/tuoluojiang/tuoluojiang22/31915

