Reputation: 671
I am fetching GPS coordinates in my xamarin.ios project using CLLocationManager, It was working fine till yesterday , today Its crashing by throwing this null exception at this line
double lat = locationManager.Location.Coordinate.Latitude;
following is my code
if (CLLocationManager.LocationServicesEnabled) {
double lat = locationManager.Location.Coordinate.Latitude;
double lon = locationManager.Location.Coordinate.Longitude;
CLLocationCoordinate2D mapCenter = new CLLocationCoordinate2D (lat, lon);
}
I have deleted the app and re installed , I have restarted the xamarin studio but no luck, could any one help me out
Upvotes: 0
Views: 462
Reputation: 9703
In your check for CLLocationManager.LocationServicesEnabled
I would also check for:
CLLocationManager.Status == CLAuthorizationStatus.AuthorizedAlways
Incase the user has declined the use of their location. Check out the enum CLAuthorizationStatus for all the different situations your app might use, e.g. AuthorizedWhenInUse
. Also check the permissions in the settings to see if your app is allowed
Upvotes: 1