コード例 #1
0
        /// <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);
            }
        }
コード例 #2
0
ファイル: TransitInfo.cs プロジェクト: pdz8/ms13apphack
        /// <summary>
        /// Finds the nearest matching route
        /// </summary>
        /// <param name="routeName">Name of route</param>
        /// <returns></returns>
        private static async Task <BusRoute> GetNearestMatchingRoute(string routeName)
        {
            BusRoute retRoute = null;

            if (RouteIDs.ContainsKey(routeName))
            {
                if (RouteIDs[routeName].Count == 0)
                {
                    return(null);
                }
                if (RouteIDs[routeName].Count == 1)
                {
                    if (!AppSettings.KnownRoutes.Value.ContainsKey(RouteIDs[routeName][0]))
                    {
                        return(null);
                    }
                    retRoute = await TransitLoader.GetRoute(RouteIDs[routeName][0]);

                    return(retRoute);
                }

                double minDist = double.PositiveInfinity;
                foreach (string id in RouteIDs[routeName])
                {
                    if (!AppSettings.KnownRoutes.Value.ContainsKey(id))
                    {
                        return(retRoute);
                    }
                    var br = AppSettings.KnownRoutes.Value[id];
                    if (br.Stop_Ids == null || br.Stop_Ids.Count == 0)
                    {
                        return(retRoute);
                    }

                    BusStop firststop = await TransitLoader.GetStop(br.Stop_Ids[0]);

                    if (firststop == null)
                    {
                        continue;
                    }
                    var dist = MyLocation.GetDistanceTo(firststop.Location);
                    if (minDist > dist)
                    {
                        retRoute = br;
                        minDist  = dist;
                    }
                }
                return(retRoute);
            }
            return(null);
        }