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

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

You May Also Like

This blog post will guide you through several effective methods to troubleshoot and resolve the issue of Microsoft Edge not...
Windows 11 offers a range of audio enhancements that can enrich your listening experience. These enhancements include features like virtual...
Windows 11 brings a fresh and visually stunning design to your desktop, and one of the standout features is the...