Пример #1
0
        public static double DistanceBetweenCoord(GpsCoord pos1, GpsCoord pos2)
        {
            double deltaLat;
              double deltaLong;
              double dist;
              double a;
              double c;

              deltaLong = pos2.Longitude - pos1.Longitude;
              deltaLat = pos2.Latitude - pos1.Latitude;

              a = System.Math.Pow(System.Math.Sin(DegToRad(deltaLat) / 2), 2) +
              System.Math.Cos(DegToRad(pos1.Latitude)) * System.Math.Cos(DegToRad(pos2.Latitude)) * System.Math.Pow(System.Math.Sin(DegToRad(deltaLong) / 2), 2);

              c = 2 * System.Math.Atan2(System.Math.Sqrt(a), System.Math.Sqrt(1 - a));

              dist = 6373 * c;

              return dist;
        }
Пример #2
0
 public static double DistanceBetweenGpsCoordFast(GpsCoord pos1, GpsCoord pos2)
 {
     double x = ((pos2.Longitude * DEGTORAD) - (pos1.Longitude * DEGTORAD)) * System.Math.Cos(((pos2.Latitude * DEGTORAD) + (pos1.Latitude * DEGTORAD)) / 2.0);
       double y = (pos2.Latitude * DEGTORAD) - (pos1.Latitude * DEGTORAD);
       return System.Math.Sqrt((x * x) + (y * y)) * RAYON_TERRE_KM * KM_M_FACTOR;
 }