手机考勤打卡 指定范围打卡
简易人事考勤系统,指定办公区域 200米或几百米之间打卡,非常适合小型企业,或劳务形式的打卡, 指定工人到固定地点打卡。 若想了解或使用项目,具体可以咨询我。
周边两点距离计算, 一般有多种方法, 这里说两种 根据勾股定律 或 使用Haversine算法。
经过测试, 两者之间, 在1000米内 误差不大, 若到了4公里, 则接近300米的误差。
勾股定律算法:
Math.sqrt(Math.pow(3,2)+Math.pow(4,2))
Haversine:
公式:
代码:
toRadians(degrees) {
return degrees * Math.PI / 180;
},
getDistance(lat1, lon1, lat2, lon2) {
// 使用 Haversine 公式计算距离
const R = 6371; // 地球半径,单位为千米
const dLat = this.toRadians(lat2 - lat1);
const dLon = this.toRadians(lon2 - lon1);
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(this.toRadians(lat1)) * Math.cos(this.toRadians(lat2)) *
Math.sin(dLon / 2) * Math.sin(dLon / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
const distance = R * c; // 距离,单位为千米
return distance;
},