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’ll learn about the Win32 Error “0x000019E5 – ERROR_COULD_NOT_RESIZE_LOG” that you get when debugging system erors in...
In this post, you’ll learn about the error “CO_E_DBERROR 0x8004E02B” that is returned when working with COM based APIs or...
In this post, you’ll learn about the Win32 Error “0x000019D0 – ERROR_LOG_BLOCK_VERSION” that you get when debugging system erors in...