计算两GPS点之间的距离的Java代码(比较精确)

jopen 11年前

        public static double getDistanceFromXtoY(double lat_a, double lng_a, double lat_b, double lng_b)          {              double pk = (double)(180 / 3.14169);                  double a1 = lat_a / pk;              double a2 = lng_a / pk;              double b1 = lat_b / pk;              double b2 = lng_b / pk;                  double t1 = Math.Cos(a1) * Math.Cos(a2) * Math.Cos(b1) * Math.Cos(b2);              double t2 = Math.Cos(a1) * Math.Sin(a2) * Math.Cos(b1) * Math.Sin(b2);              double t3 = Math.Sin(a1) * Math.Sin(b1);              double tt = Math.Acos(t1 + t2 + t3);                  return 6366000 * tt;          }