This commit is contained in:
2023-10-08 22:53:13 +08:00
parent b883b02fb9
commit e36d60d015
83 changed files with 18303 additions and 9590 deletions

View File

@@ -1,26 +1,20 @@
import { showToast, navigateBack } from "@tarojs/taro";
// 经纬度计算距离
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);
la1: number,
lo1: number,
la2: number,
lo2: number
): any {
var radLat1 = la1 * Math.PI / 180.0;
var radLat2 = la2 * Math.PI / 180.0;
var a = radLat1 - radLat2;
var b = lo1 * Math.PI / 180.0 - lo2 * Math.PI / 180.0;
var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
s = s * 6378.137;
s = Math.round(s * 10000) / 10000;
return s.toFixed(2) + 'km'
}
// 将角度转换为弧度