"use strict";
function CalculateDistance(point1, point2) {
  if (!point1 || !point2) {
    console.error("坐标点不能为空");
    return 0;
  }
  console.log("point1", point1);
  console.log("point2", point2);
  const lat1 = Number(point1.latitude);
  const lng1 = Number(point1.longitude);
  const lat2 = Number(point2.latitude);
  const lng2 = Number(point2.longitude);
  if (isNaN(lat1) || isNaN(lng1) || isNaN(lat2) || isNaN(lng2) || lat1 < -90 || lat1 > 90 || lat2 < -90 || lat2 > 90 || lng1 < -180 || lng1 > 180 || lng2 < -180 || lng2 > 180) {
    console.error("无效的坐标值", { lat1, lng1, lat2, lng2 });
    return 0;
  }
  if (lat1 === lat2 && lng1 === lng2) {
    return 0;
  }
  const R = 63710087714e-4;
  const toRadians = (degree) => degree * (Math.PI / 180);
  const φ1 = toRadians(lat1);
  const φ2 = toRadians(lat2);
  const Δφ = toRadians(lat2 - lat1);
  const Δλ = toRadians(lng2 - lng1);
  const sinHalfΔφ = Math.sin(Δφ / 2);
  const sinHalfΔλ = Math.sin(Δλ / 2);
  const a = sinHalfΔφ * sinHalfΔφ + Math.cos(φ1) * Math.cos(φ2) * sinHalfΔλ * sinHalfΔλ;
  const aClamped = Math.min(Math.max(a, 0), 1);
  const c = 2 * Math.atan2(Math.sqrt(aClamped), Math.sqrt(1 - aClamped));
  const distance = R * c;
  let s = Math.round(distance * 100) / 100;
  console.log("distancew误差", s);
  return s;
}
exports.CalculateDistance = CalculateDistance;
