public void Should_be_able_to_get_nearest_Norwegian_airport()
        {
            var home = new Location(63.433281, 10.419294);
            Airport airport = service.GetNearestAirport(home);

            Assert.AreEqual("TRD", airport.Code);
        }
Beispiel #2
0
        public void Can_get_the_distance_between_two_positions()
        {
            var posA = new Location(70.0, 24.0);
            var posB = new Location(65, 15);

            double distance = posA.DistanceTo(posB);
            Assert.IsTrue(distance > 670);
        }
Beispiel #3
0
        public void Can_get_distance_to_airport()
        {
            var altaAirport = new Airport("ALF", "Alta", 69.9792675, 23.3570997);
            var home = new Location(63.433281, 10.419294);
            var distance = altaAirport.DistanceFrom(home);

            Assert.IsTrue(distance > 670);
        }
        public void Should_find_nearest_airport_if_user_selects_that_option()
        {
            var home = new Location(63.433281, 10.419294);
            locationService.LocationToReturn = home;

            Airport nearestAirport = null;
            Messenger.Default.Register(this, (AirportSelectedMessage e) => nearestAirport = e.Content);
            Messenger.Default.Send(new FindNearestAirportMessage());

            EnqueueConditional(() => nearestAirport != null);
            EnqueueCallback(() => Assert.AreEqual("TRD", nearestAirport.Code));
            EnqueueTestComplete();
        }
Beispiel #5
0
        // Implementation of the Haversine Forumla (http://en.wikipedia.org/wiki/Haversine_formula)
        public double DistanceTo(Location to)
        {
            double R = 6378.1; // radius of earth.

            double dLat = ToRadian(to.Latitude - Latitude);
            double dLon = ToRadian(to.Longitude - Longitude);

            double a =
                Math.Sin(dLat/2.0)*Math.Sin(dLat/2.0) +
                Math.Cos(ToRadian(Latitude))*Math.Cos(ToRadian(to.Latitude))*
                Math.Sin(dLon/2.0)*Math.Sin(dLon/2.0);

            double c = 2.0*Math.Asin(Math.Min(1, Math.Sqrt(a)));
            double d = R*c;
            return d;
        }
        public Airport GetNearestAirport(Location home)
        {
            double shortestDistance = Double.MaxValue;
            Airport nearest = null;

            foreach(var airport in GetNorwegianAirports())
            {
                var distanceToAirport = airport.DistanceFrom(home);
                if(shortestDistance > distanceToAirport)
                {
                    shortestDistance = distanceToAirport;
                    nearest = airport;
                }
            }

            return nearest;
        }
 public PresetLocationService(double latitude, double longitude)
 {
     _currentLocation = new Location(latitude, longitude);
 }
 public Airport GetNearestAirport(Location home)
 {
     throw new NotImplementedException();
 }