Example #1
0
        async void _instance_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
        {
            //Console.WriteLine(e.Position.Location.Latitude.ToString("0.000"));
            //Console.WriteLine(e.Position.Location.Longitude.ToString("0.000"));

            try
            {
                var list = await Task.Run(() =>
                {
                    CurrentLocation = args.Position.Coordinate;

                    var stationList = StationNameService.GetStations();

                    //int take = TakeLimit.HasValue ? TakeLimit.Value : 2;

                    foreach (var x in stationList)
                    {
                        CalcDistance(x);
                    }
                    return(stationList.OrderBy(x => x.Distance).Take(10));
                });

                DispatcherHelper.UIDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    Stations = list;
                });
            }
            catch { }
        }
        async void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs <GeoCoordinate> e)
        {
            //Console.WriteLine(e.Position.Location.Latitude.ToString("0.000"));
            //Console.WriteLine(e.Position.Location.Longitude.ToString("0.000"));

            try
            {
                var list = await Task.Run(() =>
                {
                    CurrentLocation = e.Position.Location;

                    var stationList = StationNameService.GetStations();

                    //int take = TakeLimit.HasValue ? TakeLimit.Value : 2;


                    stationList.ForEach(x => CalcDistance(x));
                    return(stationList.OrderBy(x => x.Distance).Take(10));
                });

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    Stations = list;
                });
            }
            catch { }
        }
        internal void SeachStation(string p)
        {
            if (string.IsNullOrEmpty(p))
            {
                StationList.Clear();
            }
            else
            {
                p = p.ToLower();


                var stations = StationNameService.GetStations().Where(x => x.Name.ToLower().StartsWith(p)).OrderBy(x => x.Sort).Take(7);

                if (stations.Count() < 7)
                {
                    var extraStations = StationNameService.GetStations().Where(x => x.StartsWith(p)).OrderBy(x => x.Sort).Take(7 - stations.Count());

                    stations = stations.Union(extraStations);
                }

                StationList.Clear();

                foreach (var s in stations)
                {
                    StationList.Add(s);
                }
            }
        }
        internal void LoadForPicker()
        {
            if (Stations == null)
            {
                var all = StationNameService.GetStations();

                Stations = AlphaKeyGroup <Station> .CreateGroups(
                    all,
                    (Station s) => { return(s.Name); },
                    true);
            }
        }
        /// <summary>
        /// Search a station
        /// </summary>
        /// <param name="p"></param>
        internal void SeachStation(string p)
        {
            if (string.IsNullOrEmpty(p))
            {
                StationList.Clear();

                ShowFavoriteStations();
            }
            else
            {
                p = p.ToLower();

                //Do a normal starts with
                var stations = StationNameService.GetStations().Where(x => x.Name.ToLower().StartsWith(p)).OrderBy(x => x.Sort).Take(8);

                if (stations.Count() < 8)
                {
                    //Search extra names codes etc
                    var extraStations = StationNameService.GetStations().Where(x => x.StartsWith(p)).OrderBy(x => x.Sort).Take(8 - stations.Count());

                    stations = stations.Union(extraStations);
                }

                //No results? Search international
                if (stations.Count() <= 2)
                {
                    //Search extra names codes etc
                    var extraStations = StationNameService.GetStations(true).Where(x => x.StartsWith(p)).OrderBy(x => x.Sort).Take(8);

                    //Remove stations already found from extraStations
                    var dubbel = extraStations.Where(x => stations.Select(s => s.Code).Contains(x.Code)).ToList();
                    extraStations = extraStations.Except(dubbel);

                    stations = stations.Union(extraStations);
                }

                StationList.Clear();

                foreach (var station in stations)
                {
                    StationList.Add(station);
                }
            }
        }