I'm making a windows phone app which displays where the closest campus shuttles are (among other things). Windows Phone requires apps to allow the users to turn off location services within the app.
So, I added a toggle for it on a settings page, but it doesn't seem to do anything.
Here's the viewmodel where I declared the geocoordinatewatcher.
public MainViewModel() { geoWatcher = new GeoCoordinateWatcher(); if (geoWatcher.TryStart(false, TimeSpan.FromSeconds(30) )==false ) { MessageBox.Show("The location services are disabled for this app. We can't detect the nearby stops. To turn location services back on, go to the settings page.", "Warning", MessageBoxButton.OK); } } private GeoCoordinateWatcher geoWatcher; public GeoCoordinateWatcher GeoWatcher { get { return geoWatcher; } set { if (geoWatcher != value) { geoWatcher = value; NotifyPropertyChanged("GeoWatcher"); } if(geoWatcher.Status== GeoPositionStatus.Disabled) { geoWatcher.Stop(); } } }
and here's the bulk of the settings page
public SettingsPage() { InitializeComponent(); if (App.ViewModel.GeoWatcher.Status == GeoPositionStatus.Ready) { locToggle.IsChecked = true; locToggle.Content = "On"; } else { locToggle.IsChecked = false; locToggle.Content = "Off"; } } private void toggleChecked(object sender, RoutedEventArgs e) { locToggle.Content = "On"; App.ViewModel.GeoWatcher.Start(); MessageBox.Show("this is the status " + App.ViewModel.GeoWatcher.Status.ToString(), "Info", MessageBoxButton.OK); //for debugging } private void toggleUnchecked(object sender, RoutedEventArgs e) { locToggle.Content = "Off"; App.ViewModel.GeoWatcher.Stop(); MessageBox.Show("this is the status " + App.ViewModel.GeoWatcher.Status.ToString(), "Info", MessageBoxButton.OK); //for debugging }
When i turn the toggle off and click away from the Settings page, and go back to it, the toggle is re-enabled again.
I tried putting in a message box on the functions to debug but the status always says "Ready" and my app still uses the location services, even when I turn the toggle to "off".
Is there something I should be adding to the code so that the toggle will properly make my app stop using location services across my app if it's disabled on the settings page? Or should I be checking something else besides GeoPositionStatus? I couldn't figure out a way to make my app actually change the location services permissions or PositionStatus.
I looked at this page here, but am still confused since I followed the example at the bottom of the page, to no avail. I searched StackOverflow but I couldn't seem to find a similar question with WP. I also posted this on the AppHub forums though.
Thanks!