/// <summary> /// Get all stops that the route visits /// </summary> /// <returns></returns> public async Task GetStopsOfRoute() { List <BusStop> stopList = new List <BusStop>(); if (this.Context == null) { return; } if (this.Context.Stop_Ids == null) { return; } NumStopsVisibility = Visibility.Visible; NumStops = 0; foreach (string id in this.Context.Stop_Ids) { BusStop stop; if (AppSettings.KnownStops.Value.ContainsKey(id)) { stop = AppSettings.KnownStops.Value[id]; } else { stop = await TransitLoader.GetStop(id); if (stop == null) { break; } await TransitLoader.GetTransitNetwork(stop.Location); } stopList.Add(stop); NumStops++; } NumStopsVisibility = Visibility.Collapsed; // Update Stops Observable Collection if (LocationTracker.Location != null) { stopList = stopList.OrderBy(s => LocationTracker.Location.GetDistanceTo(s.Location)).ToList(); } int numbering = 0; foreach (BusStop bs in stopList) { numbering++; bs.Number = numbering; this.Stops.Add(bs); } }
/// <summary> /// Search for route within known routes. /// If not found, load up nearby transit info and search again. /// TODO: If there is a known far away stop, this will fail. /// </summary> /// <param name="routeName"></param> /// <returns></returns> public static async Task <BusRoute> SearchForRoute(string routeName) { BusRoute result = null; result = await GetNearestMatchingRoute(routeName); if (result != null) { return(result); } if (MyLocation != null) { await TransitLoader.GetTransitNetwork(TransitInfo.MyLocation); } //RefreshRouteIDs(); await RefreshRouteIDsAsync(); result = await GetNearestMatchingRoute(routeName); return(result); }