Ejemplo n.º 1
0
        /// <summary>
        /// Create a new GeoLocation from lat/long in degrees
        /// </summary>
        /// <param name="latitude">The latitude.</param>
        /// <param name="longitude">The longitude.</param>
        /// <returns></returns>
        public static GeoLocation FromDegrees(double latitude, double longitude)
        {
            var geo = new GeoLocation
            {
                Latitude = latitude,
                Longitude = longitude
            };

            geo.CheckBounds();

            return geo;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculate the great circle distance between this location and another location.
        /// <seealso cref="http://en.wikipedia.org/wiki/Great-circle_distance"/>
        /// </summary>
        /// <param name="location">The location.</param>
        /// <param name="radius">The radius of the sphere in KM. This defaults to the Earth's radius (6371.01km).</param>
        /// <returns></returns>
        public double GetDistanceTo(GeoLocation location, double radius = 6371.01)
        {
            if (radius < 0d) throw new ArgumentException("Radius must be greater than zero");

            return Math.Acos(Math.Sin(LatitudeRadians) * Math.Sin(location.LatitudeRadians) +
                             Math.Cos(LatitudeRadians) * Math.Cos(location.LatitudeRadians) *
                             Math.Cos(LongitudeRadians - location.LongitudeRadians)) * radius;
        }
Ejemplo n.º 3
0
        public void TestGetDistanceToRadiusLessThanZero()
        {
            var toLocation = GeoLocation.FromDegrees(20, 20);

            Assert.Throws <ArgumentException>(() => location.GetDistanceTo(toLocation, -1), "Radius must be greater than zero");
        }
Ejemplo n.º 4
0
        public void TestConstructorFromDegreesLongitudeTooLarge()
        {
            var exception = Assert.Throws <ArgumentException>(() => GeoLocation.FromDegrees(1, 185));

            Assert.AreEqual(exception.Message, "Longitude must not be greater than the maximum value. (180)");
        }
Ejemplo n.º 5
0
        public void TestConstructorFromDegreesLongitudeTooSmall()
        {
            var exception = Assert.Throws <ArgumentException>(() => GeoLocation.FromDegrees(1, -185));

            Assert.AreEqual(exception.Message, "Longitude must not be less than the minimum value. (-180)");
        }
Ejemplo n.º 6
0
 public void Setup()
 {
     location = GeoLocation.FromDegrees(0, 0);
 }
Ejemplo n.º 7
0
 public void Setup()
 {
     location = GeoLocation.FromDegrees(0, 0);
 }