Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to check whether the location services are active?

is it possible to check whether the location services are active?

I mean Settings > Location > Location services

There is probably no direct API for calling, but could it work with the GeoCoordinateWatcher?

like image 331
user598328 Avatar asked Feb 03 '11 13:02

user598328


2 Answers

            GeoCoordinateWatcher g = new GeoCoordinateWatcher();
            g.Start();
            if (g.Permission.Equals(GeoPositionPermission.Granted))
            {
                //Your location services is enabled. Go ahead.
                //Your codes goes here.
            }
            else if (g.Permission.Equals(GeoPositionPermission.Denied) || g.Permission.Equals(GeoPositionPermission.Unknown))
            {                    
                MessageBox.Show("Location services are disabled. To enable them, Goto Settings - Location - Enable Location Services.", "Location services", MessageBoxButton.OK);
            }
like image 53
TeJ Avatar answered Sep 20 '22 10:09

TeJ


You can use the following code to determine the status of the Location service:

var watcher = new GeoCoordinateWatcher();
if (GeoPositionStatus.Disabled == watcher.Status)
{
    // Watcher is disabled.
}

More realistically, you'll want to pay more attention to change to the status (just because the service isn't disabled doesn't mean you've got location data), so you shoudl take a look at the MSDN Documentation for working with the Location service.

There's also a good post on filtering and emulating location data using the Reactive extensions, which is perfect for that pre-device testing, though to save you time on that front the Widnows Phone Team have released the Windows Phone GPS Emulator.

like image 23
Derek Lakin Avatar answered Sep 20 '22 10:09

Derek Lakin