Exemplo n.º 1
0
        /// <summary>
        /// Calculates the distance between two GPS points, and returns a Distance object.
        /// </summary>
        /// <param name="objStart">Coordinate 1</param>
        /// <param name="objEnd">Coordinate 2</param>
        /// <returns>Distance</returns>
        public static Distance GetDistance(GPSCoordinate objStart, GPSCoordinate objEnd)
        {
            ///Credits to John Bowen for the formula in C# syntax
            ///http://blog.gobowen.org/
            ///
            ///Credits to 'The Math Forum' for the formula
            ///http://mathforum.org/library/drmath/view/51879.html

            double degrad = Math.PI / 180;
            double a, c, R;

            R = 0;
            double lat1, lon1;
            double lat2, lon2;
            double dlon, dlat;

            //convert the degree values to radians before calculation
            lat1 = objStart.Latitude * degrad;
            lon1 = objStart.Longitude * degrad;
            lat2 = objEnd.Latitude * degrad;
            lon2 = objEnd.Longitude * degrad;

            dlon = lon2 - lon1;
            dlat = lat2 - lat1;

            a = Math.Pow(Math.Sin(dlat / 2), 2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Pow(Math.Sin(dlon / 2), 2);
            c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));

            // R (Earth Radius) 6367.0 km
            R = 6367.0;
            return(new Kilometre(R * c));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculates the distance between two GPS points, and returns a Distance object.
        /// </summary>
        /// <param name="objStart">Coordinate 1</param>
        /// <param name="objEnd">Coordinate 2</param>
        /// <returns>Distance</returns>
        public static Distance GetDistance(GPSCoordinate objStart, GPSCoordinate objEnd)
        {
            ///Credits to John Bowen for the formula in C# syntax
            ///http://blog.gobowen.org/
            ///
            ///Credits to 'The Math Forum' for the formula
            ///http://mathforum.org/library/drmath/view/51879.html

            double degrad = Math.PI/180;
            double a, c, R;
            R = 0;
            double lat1, lon1;
            double lat2, lon2;
            double dlon, dlat;

            //convert the degree values to radians before calculation
            lat1 = objStart.Latitude * degrad;
            lon1 = objStart.Longitude * degrad;
            lat2 = objEnd.Latitude * degrad;
            lon2 = objEnd.Longitude * degrad;

            dlon = lon2 - lon1;
            dlat = lat2 - lat1;

            a = Math.Pow(Math.Sin(dlat/2),2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Pow(Math.Sin(dlon/2),2);
            c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1-a)) ;

            // R (Earth Radius) 6367.0 km
            R = 6367.0;
            return new Kilometre(R * c);
        }