Reputation: 1636
Hi I am trying to build one Application in Xamarin forms which has huge dependency on location services.
Using Xamarin.Essentials I am able to get the location, but in Android its give the last known location and sometime its not that much accurate.
Problem 1.
But I am not able to add Location Listener so that once user change location, I can get notified.
Problem 2. How to exactly know whether user has disabled Phone Location or App Location ?
Please guide me.. Thanks in advance
Upvotes: 0
Views: 1561
Reputation: 2087
Problem #1
I don't know, but i think Xamarin.Essentials doesn't have Location Listener feature yet, might be wrong, but you can use this plugin from jamesmontemagno (also a main developer of Xamarin.Essentials), this plugin can track geolocation changes like this:
CrossGeolocator.Current.IsListening
Problem #2
Following the documentation here, you receive an exception for the following cases: permission was not granted or if the location is not enabled/supported
try
{
var location = await Geolocation.GetLastKnownLocationAsync();
if (location != null)
{
Console.WriteLine($"Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}");
}
}
catch (FeatureNotSupportedException fnsEx)
{
// Handle not supported on device exception
}
catch (FeatureNotEnabledException fneEx)
{
// Handle not enabled on device exception
}
catch (PermissionException pEx)
{
// Handle permission exception
}
catch (Exception ex)
{
// Unable to get location
}
Upvotes: 2