Esempio n. 1
0
        private void ShowDepartures(string to, bool actSilently)
        {
            var currentPosition = LocationService.CurrentPosition;

            if (currentPosition != null && !currentPosition.IsUnknown)
            {
                var from = Stations.GetNearest(LatLong.Create(currentPosition.Latitude, currentPosition.Longitude), 1)[0];
                ShowDepartures(Stations.GetAll(), from.Item2, null, to, actSilently);
            }
            else
            {
                OnError();
            }
        }
Esempio n. 2
0
 private static void OnGeoPositionChanged(object sender, GeoPositionChangedEventArgs <GeoCoordinate> e)
 {
     if (e.Position.Timestamp > currentPositionTimestamp)
     {
         var previousPosition = CurrentPosition;
         var newPosition      = e.Position.Location;
         if (previousPosition == null || previousPosition.IsUnknown || currentPositionTimestamp == default(DateTimeOffset) ||
             LatLong.Create(previousPosition.Latitude, previousPosition.Longitude) - LatLong.Create(newPosition.Latitude, newPosition.Longitude) >= 0.050)
         {
             CurrentPosition = newPosition;
             Settings.Set(Setting.CurrentLat, CurrentPosition.Latitude);
             Settings.Set(Setting.CurrentLong, CurrentPosition.Longitude);
             if (PositionChanged != null && !AppMetadata.Current.RunningInBackground)
             {
                 PositionChanged();
             }
         }
         currentPositionTimestamp = e.Position.Timestamp;
     }
 }
Esempio n. 3
0
        private void LoadNearestStations()
        {
            if (nearestLazyBlock != null)
            {
                nearestLazyBlock.Cancel();
            }

            var lazyBlockUI = new LazyBlockUI <Tuple <double, Station> >(this, nearestStations, nearestStationsMessageTextBlock, null);

            LatLong from;

            if (fromStation == null)
            {
                var currentPosition = LocationService.CurrentPosition;
                if (!Settings.GetBool(Setting.LocationServicesEnabled))
                {
                    lazyBlockUI.SetItems(null);
                    lazyBlockUI.SetLocalProgressMessage("Locations Services are disabled.\nYou can enable them in the Settings.");
                    nearestLazyBlock = null;
                    return;
                }
                else if (currentPosition == null || currentPosition.IsUnknown)
                {
                    lazyBlockUI.SetLocalProgressMessage("Acquiring position...");
                    lazyBlockUI.SetGlobalProgressMessage("Acquiring position...");
                    nearestLazyBlock = null;
                    return;
                }
                from = LatLong.Create(currentPosition.Latitude, currentPosition.Longitude);
            }
            else
            {
                from = fromStation.Location;
            }

            lazyBlockUI.SetLocalProgressMessage("");
            lazyBlockUI.SetGlobalProgressMessage("");

            nearestLazyBlock = new LazyBlock <Tuple <double, Station>[]>(
                "nearest stations",
                "No nearby stations",
                Stations.GetNearestAsync(from, 150),
                items => items.Length == 0,
                lazyBlockUI,
                false,
                null,
                null,
                nearestUnfiltered =>
            {
                var nearestFiltered = nearestUnfiltered.AsEnumerable();
                if (fromStation != null)
                {
                    nearestFiltered = nearestFiltered.Where(t => t.Item2.Code != fromStation.Code);
                }
                if (excludeStation != null)
                {
                    nearestFiltered = nearestFiltered.Where(t => t.Item2.Code != excludeStation);
                }
                return(nearestFiltered.ToArray());
            });
        }