How to Find if the Location Services are Turned Off in Windows Phone using C# ?

There are times when you want to know if the location services are turned on/off from your Windows Phone app and take the action based on it .

The Geolocator class in Windows Phone 8 SDK provides the property “LocationStatus” which can be used to know if the Location Services are Turned On/Off .

The LocationStatus value takes “PositionStatus.Disabled” when the Location Services are turned off by the user .

How to Find if the Location Services are Turned Off in Windows Phone using C# ?

Below is a sample class that provides the property IsLocationServiceEnabled which returns false when the Location Services are Turned Off by the user in the device.

public class LocationService
{
  public bool IsLocationServiceEnabled
  {
   get
   {
     Geolocator locationservice = new Geolocator();
     if (locationservice.LocationStatus == PositionStatus.Disabled)
     {
      return false;
     }
     return true;
   }
  }
}

Find the status of the LocationService

LocationService service = new LocationService();
MessageBox.Show(service.IsLocationServiceEnabled.ToString());

How to Find if the Location Services are Turned Off in Windows Phone using C# ?

The above method is just one of the ways that i was able to explore on finding the Location Service status programmatically . Feel free to share any other better solution in the comments section . I will be happy to update the blog post based on it.

    2 Comments

  1. Rohit
    August 28, 2014
    Reply

    Really Nice Article.. 🙂

  2. Nice Article.
    How to find location service is on/off throughout the app?

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this post, you will learn about sync provider notifications in Windows 11 and how to disable or enable it...
In this tutorial, let’s learn how to enable or disable the startup sound in Windows 11. By default, when Windows...
The CameraCaptureTask allows the Windows Phone 7 App to launch the Camera Application . This will be useful when the...