Currently using a Samsung Galaxy S10.
I am seeing something strange with Gelocation.
I send the request the first time and it comes back almost immediately.....and altitude is null.
I press the button again, the request takes longer and altitude is returned.
Why????
public static async Task GetCurrentLocation()
{
Location location = null;
string title = "Geo Location Services";
try { GeolocationRequest request = new GeolocationRequest(GeolocationAccuracy.Best, new TimeSpan(0,0,0,10)); location = await Geolocation.GetLocationAsync(request); } catch (FeatureNotSupportedException fnsEx) { App.logger.Error($"Location Untility GetCurrentLocation: {fnsEx.Message.ToString()}"); await Application.Current.MainPage.DisplayAlert(title, "Feature not suppported.", "Ok"); } catch (FeatureNotEnabledException fneEx) { App.logger.Error($"Location Untility GetCurrentLocation: {fneEx.Message.ToString()}"); await Application.Current.MainPage.DisplayAlert(title, "Feature not enabled.", "Ok"); } catch (PermissionException pEx) { App.logger.Error($"Location Untility GetCurrentLocation: {pEx.Message.ToString()}"); await Application.Current.MainPage.DisplayAlert(title, "Feature permission not granted.", "Ok"); } catch (Exception ex) { App.logger.Error($"Location Untility GetCurrentLocation: {ex.Message.ToString()}"); await Application.Current.MainPage.DisplayAlert(title, "Feature not available.", "Ok"); } return location; }
Answers
I see you set
best Accuracy
when requesting location , can you switch the Accuracy toMedium
in code or select High Accuracy in device settings , refer to here .If problem persists i suggest you use Xam.Plugin.Geolocator , refer to here .