This commit is contained in:
2023-08-15 13:30:58 +08:00
parent c081f0fc29
commit b444858bda
30 changed files with 984 additions and 3 deletions

29
src/utils/index.ts Normal file
View File

@@ -0,0 +1,29 @@
// 经纬度计算距离
export function calculateDistance(
lat1: number,
lon1: number,
lat2: number,
lon2: number
): string {
const R = 6371; // 地球平均半径(单位:千米)
const dLat = toRadians(lat2 - lat1);
const dLon = toRadians(lon2 - lon1);
const a =
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(toRadians(lat1)) *
Math.cos(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.toFixed(2);
}
// 将角度转换为弧度
function toRadians(degrees: number): number {
return (degrees * Math.PI) / 180;
}