How to check whether Location Service is Disabled in WP8?

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
    // 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.

If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter , Facebook , Google+ and LinkedIn . I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.


© 2008-2016 - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top