// Finds the bus route that matches the route short name and finds the closest // bus stop that contains the route. // Returns a tuple of the user's Route and the nearest Stop in a 1800-meter radius public async Task <(Route route, Stop stop)> GetRouteAndStopForLocation(string routeShortName, string lat, string lon) { (Route, List <Stop> stops)routeAndStops = await GetStopsForRoute(routeShortName, lat, lon); if (routeAndStops.Item1 == null || routeAndStops.Item2 == null) { throw new ArgumentException("No stops were found within a mile of your location for your bus route."); } //Stop minDistStop = routeAndStops.Item2.First(); // demo pythia in claculate distance // demo linq query to foreach (want to step into method, so to set easier breakpoint convert to foreach) //var minDistance = routeAndStops.stops.Min(s => GeocodeHelpers.CalculateDistance(lat, lon, s.Lat, s.Lon)); var min = (from stop in routeAndStops.stops select GeocodeHelpers.CalculateDistance(lat, lon, stop.Lat, stop.Lon)).Min(); Stop minDistStop = routeAndStops.stops.Where(x => GeocodeHelpers.CalculateDistance(lat, lon, x.Lat, x.Lon) == min).FirstOrDefault(); return(routeAndStops.Item1, minDistStop); }