///
        /// Taken from http://stackoverflow.com/questions/238260/how-to-calculate-the-bounding-box-for-a-given-lat-lng-location?lq=1
        /// See also http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates
        // 'halfSideInKm' is the half length of the bounding box you want in kilometers.

        /// <summary>
        /// Compute the a box around the center point of 2x halfSideInKm.
        /// </summary>
        /// <param name="point">Center point to build a box around</param>
        /// <param name="halfSideInKm">Half the size of the width/height of the box.</param>
        /// <returns></returns>
        public static LocationBoundry ComputeBoundry(LatLongPoint point, double halfSideInKm)
        {
            // Bounding box surrounding the point at given coordinates,
            // assuming local approximation of Earth surface as a sphere
            // of radius given by WGS84
            var latitude  = LocationHelper.DegreesToRadians(point.Latitude);
            var longitude = LocationHelper.DegreesToRadians(point.Longitude);
            var halfSide  = 1000 * halfSideInKm;

            // Radius of Earth at given latitude
            var radius = WGS84EarthRadius(latitude);
            // Radius of the parallel at given latitude
            var pradius = radius * Math.Cos(latitude);

            var latMin = latitude - halfSide / radius;
            var latMax = latitude + halfSide / radius;
            var lonMin = longitude - halfSide / pradius;
            var lonMax = longitude + halfSide / pradius;

            return(new LocationBoundry
            {
                NorthEast = new LatLongPoint
                {
                    Latitude = LocationHelper.RadiansToDegrees(latMax),
                    Longitude = LocationHelper.RadiansToDegrees(lonMax)
                },
                SouthWest = new LatLongPoint
                {
                    Latitude = LocationHelper.RadiansToDegrees(latMin),
                    Longitude = LocationHelper.RadiansToDegrees(lonMin)
                }
            });
        }
Exemple #2
0
        public Distance ComputeDistanceAway(LatLongPoint from)
        {
            LatLongPoint stationPoint = new LatLongPoint(Place.Lattitude, Place.Longitude);

            return(LocationHelper.ComputeDistance(stationPoint, from));
        }