コード例 #1
0
ファイル: GeoLocation.cs プロジェクト: comsechq/sugar
        /// <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;
        }
コード例 #2
0
ファイル: GeoLocation.cs プロジェクト: comsechq/sugar
        /// <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;
        }
コード例 #3
0
        public void TestGetDistanceToRadiusLessThanZero()
        {
            var toLocation = GeoLocation.FromDegrees(20, 20);

            Assert.Throws <ArgumentException>(() => location.GetDistanceTo(toLocation, -1), "Radius must be greater than zero");
        }
コード例 #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)");
        }
コード例 #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)");
        }
コード例 #6
0
 public void Setup()
 {
     location = GeoLocation.FromDegrees(0, 0);
 }
コード例 #7
0
ファイル: GeoLocationTest.cs プロジェクト: comsechq/sugar
 public void Setup()
 {
     location = GeoLocation.FromDegrees(0, 0);
 }