Ejemplo n.º 1
0
        public Airport GetClosestAirport(GeoCoordinate coordinate)
        {
            // Assign it to first airport to avoid linting errors
            Airport closestAirport = AirportList[0];
            double  minDist        = Double.MaxValue;

            foreach (var airport in AirportList)
            {
                string        latlong         = airport.Latitude.ToString() + "," + airport.Longitude.ToString();
                GeoCoordinate airportLocation = GeoCoordinate.FromLatitudeAndLongitudeString(latlong);
                double        tempDist        = coordinate.GetDistanceTo(airportLocation);
                if (tempDist < minDist)
                {
                    minDist        = tempDist;
                    closestAirport = airport;
                }
            }

            return(closestAirport);
        }