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());
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
Really Nice Article.. 🙂
Nice Article.
How to find location service is on/off throughout the app?