If you are building Location Aware app for Windows Phone 8, you might want to check whether the Location Service is enabled/disabled in the system and based on that, you can take appropriate steps asking user to enable that.

 

If you are one of such developer, this small but handy blog post will help you to figure out the status of the Location Service. Continue reading to know further about it.

 

The “Location Service” page is available under the settings menu and provides user to turn ON or OFF the location service.  Sometime user disables this service to reduce the unnecessary battery uses. But in case the user downloads your Location aware application, you must have to specify some visuals to let the user know about it by providing a message in the screen, so that, he can enable it to use the app properly.

 

So, what’s needs to be done? The sealed class “Geolocator” present under “Windows.Devices.Geolocation” namespace will help you to identify whether the Location Service is turned ON or OFF. For this, first create an instance of the Geolocator class and then check the value of the “LocationStatus” property of the instance. If it is PositionStatus.Disabled, that means, the user has turned OFF the Location Service from the settings page.

 

Here is the complete code snippet for your reference:

 

// First create the instance of "Windows.Devices.Geolocation.Geolocator" class
var geoLocator = new Geolocator();
 
if (geoLocator.LocationStatus == PositionStatus.Disabled)
{
    // Location Service is turned OFF
    // Provide a visual message asking user to turn it ON
}
else
{
    // Location Service is already enabled. Proceed with your app functionality.
}

 

"Place Explorer" app for Windows Phone"Place Explorer" app for Windows Phone

 

A working copy of the above code snippet you can find in my app named “Place Explorer”. Don’t forget to try out the app in your Windows Phone 8 device.

 

I hope, this small post will help you to check whether your app can access the Location Service and based on that you can take further steps. Connect with me on Twitter and Facebook to get latest updates of my articles. Don’t forget to share this post to others.

Have a question? Or, a comment? Let's Discuss it below...

Thank you for visiting our website!

We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.

We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.