Пример #1
0
        public static ObservableCollection <BikeStationViewModel> GetNearStations(Location coordinate, IEnumerable <BikeStationViewModel> allStations, bool from)
        {
            //return collection
            ObservableCollection <BikeStationViewModel> collection = new ObservableCollection <BikeStationViewModel>();

            if (allStations != null)
            {
                List <BikeStationViewModel> stations = null;
                foreach (BikeStationViewModel station in allStations)
                {
                    if (from)
                    {
                        station.WalkDistanceTo = GeoMath.ComputeDistance(station.Location.Latitude, station.Location.Longitude, coordinate.Latitude, coordinate.Longitude);
                    }
                    else
                    {
                        station.WalkDistanceFrom = GeoMath.ComputeDistance(station.Location.Latitude, station.Location.Longitude, coordinate.Latitude, coordinate.Longitude);
                    }
                }

                if (from)
                {
                    stations = allStations.OrderBy(x => x.WalkDistanceTo).Take(5).ToList();
                }
                else
                {
                    stations = allStations.OrderBy(x => x.WalkDistanceFrom).Take(5).ToList();
                }

                foreach (BikeStationViewModel station in stations)
                {
                    collection.Add(station);
                }
            }
            else
            {
                throw new Exception(AppResources.Message_StationsNotLoaded);
            }
            return(collection);
        }