LonelySharp.GeoLocation.BoundingCoordinates C# (CSharp) Method

BoundingCoordinates() public method

Computes the bounding coordinates of all points on the surface of a sphere that have a great circle distance to the point represented by this GeoLocation instance that is less or equal to the distance argument. For more information about the formulae used in this method visit http://JanMatuschek.de/LatitudeLongitudeBoundingCoordinates
public BoundingCoordinates ( double distance ) : LonelySharp.GeoLocation[]
distance double The distance from the point represented by this /// GeoLocation instance. Must me measured in the same unit as the radius argument. ///
return LonelySharp.GeoLocation[]
        public GeoLocation[] BoundingCoordinates(double distance)
        {
            if (distance < 0d)
                throw new Exception("Distance cannot be less than 0");

            // angular distance in radians on a great circle
            double radDist = distance / earthRadius;

            double minLat = radLat - radDist;
            double maxLat = radLat + radDist;

            double minLon, maxLon;
            if (minLat > MIN_LAT && maxLat < MAX_LAT)
            {
                double deltaLon = Math.Asin(Math.Sin(radDist) /
                    Math.Cos(radLat));
                minLon = radLon - deltaLon;
                if (minLon < MIN_LON) minLon += 2d * Math.PI;
                maxLon = radLon + deltaLon;
                if (maxLon > MAX_LON) maxLon -= 2d * Math.PI;
            }
            else
            {
                // a pole is within the distance
                minLat = Math.Max(minLat, MIN_LAT);
                maxLat = Math.Min(maxLat, MAX_LAT);
                minLon = MIN_LON;
                maxLon = MAX_LON;
            }

            return new GeoLocation[]
            {
                FromRadians(minLat, minLon),
                FromRadians(maxLat, maxLon)
            };
        }

Usage Example

Exemplo n.º 1
0
        public POICollection GetPOIList(double latitude, double longitude, int distance, DistanceType distanceType)
        {
            double calculatedDistance;

            //convert it back to kilometers
            switch (distanceType)
            {
            case DistanceType.Meters:
                calculatedDistance = Convert.ToDouble((double)distance / 1000);
                break;

            case DistanceType.Miles:
                calculatedDistance = distance / 0.621371192;
                break;

            default:
                calculatedDistance = distance;
                break;
            }

            GeoLocation myLocation = GeoLocation.FromDegrees(latitude, longitude);

            GeoLocation[] coordinates = myLocation.BoundingCoordinates(calculatedDistance);

            double north = coordinates[1].getLatitudeInDegrees();
            double south = coordinates[0].getLatitudeInDegrees();
            double east  = coordinates[1].getLongitudeInDegrees();
            double west  = coordinates[0].getLongitudeInDegrees();

            return(GetPOIList(north, south, east, west));
        }