public void Initialize(AsyncOperationTracker operationTracker) { this.operationTracker = operationTracker; //#if DEBUG // if (Microsoft.Devices.Environment.DeviceType == DeviceType.Emulator) // { // //LocationTrackerStatic.LastKnownLocation = null; // Random random = new Random(); // int timeoutMs = random.Next(0, 5000); // timer = new Timer(param => // { // UIAction(() => // { // LocationTrackerStatic.LastKnownLocation = new GeoCoordinate(47.675888, -122.320763); // GeoPositionChangedEventArgs<GeoCoordinate> args = // new GeoPositionChangedEventArgs<GeoCoordinate>(new GeoPosition<GeoCoordinate>(DateTime.Now, LocationTrackerStatic.LastKnownLocation)); // LocationWatcher_LocationKnown( // this, // args // ); // locationWatcher_PositionChanged_NotifyPropertyChanged(this, args); // }); // }, // null, // timeoutMs, // Timeout.Infinite // ); // } //#endif LocationTrackerStatic.PositionChanged += new EventHandler <GeoPositionChangedEventArgs <GeoCoordinate> >(locationWatcher_PositionChanged_NotifyPropertyChanged); if (LocationKnown == false) { if (LocationTrackerStatic.LocationStatus == GeoPositionStatus.Disabled) { LocationDisabled(true); } else if (IsolatedStorageSettings.ApplicationSettings.Contains("UseLocation") && (bool)IsolatedStorageSettings.ApplicationSettings["UseLocation"] == false) { LocationDisabled(false); } else { operationTracker.WaitForOperation("LoadLocation", "Finding your location..."); locationLoading = true; LocationTrackerStatic.PositionChanged += new EventHandler <GeoPositionChangedEventArgs <GeoCoordinate> >(LocationWatcher_LocationKnown); LocationTrackerStatic.StatusChanged += new EventHandler <GeoPositionStatusChangedEventArgs>(LocationWatcher_StatusChanged); } } else { locationWatcher_PositionChanged_NotifyPropertyChanged(this, new GeoPositionChangedEventArgs <GeoCoordinate>(new GeoPosition <GeoCoordinate>(DateTime.Now, CurrentLocation))); } }
public AViewModel(IBusServiceModel busServiceModel, IAppDataModel appDataModel, ILocationModel locationModel) { this.lazyBusServiceModel = busServiceModel; this.lazyAppDataModel = appDataModel; if (!IsInDesignMode) { locationTracker = new LocationTracker(); operationTracker = new AsyncOperationTracker(); } // Set up the default action, just execute in the same thread UIAction = (uiAction => uiAction()); eventsRegistered = false; }
public void Initialize(AsyncOperationTracker operationTracker) { this.operationTracker = operationTracker; //#if DEBUG // if (Microsoft.Devices.Environment.DeviceType == DeviceType.Emulator) // { // //LocationTrackerStatic.LastKnownLocation = null; // Random random = new Random(); // int timeoutMs = random.Next(0, 5000); // timer = new Timer(param => // { // UIAction(() => // { // LocationTrackerStatic.LastKnownLocation = new GeoCoordinate(47.675888, -122.320763); // GeoPositionChangedEventArgs<GeoCoordinate> args = // new GeoPositionChangedEventArgs<GeoCoordinate>(new GeoPosition<GeoCoordinate>(DateTime.Now, LocationTrackerStatic.LastKnownLocation)); // LocationWatcher_LocationKnown( // this, // args // ); // locationWatcher_PositionChanged_NotifyPropertyChanged(this, args); // }); // }, // null, // timeoutMs, // Timeout.Infinite // ); // } //#endif LocationTrackerStatic.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(locationWatcher_PositionChanged_NotifyPropertyChanged); if (LocationKnown == false) { if (LocationTrackerStatic.LocationStatus == GeoPositionStatus.Disabled) { LocationDisabled(true); } else if (IsolatedStorageSettings.ApplicationSettings.Contains("UseLocation") && (bool)IsolatedStorageSettings.ApplicationSettings["UseLocation"] == false) { LocationDisabled(false); } else { operationTracker.WaitForOperation("LoadLocation", "Finding your location..."); locationLoading = true; LocationTrackerStatic.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(LocationWatcher_LocationKnown); LocationTrackerStatic.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(LocationWatcher_StatusChanged); } } else { locationWatcher_PositionChanged_NotifyPropertyChanged(this, new GeoPositionChangedEventArgs<GeoCoordinate>(new GeoPosition<GeoCoordinate>(DateTime.Now, CurrentLocation))); } }