GeolocatorPlugin
GeolocatorPlugin copied to clipboard
IsGeolocationEnabled always returns false
Version Number of Plugin: 4.5.0.6 Device Tested On: A-70 android Simulator Tested On: Android Version of VS: latest Version of Xamarin: latest Versions of other things you are using:
Steps to reproduce the Behavior
- Place the following code in OnrequestPermissionResult: PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
- Place following code in constructor of android project: CrossCurrentActivity.Current.Init(this, savedInstanceState);
- Place following code in constructor of android project: Xamarin.Essentials.Platform.Init(this, savedInstanceState);
- Ask for location permission
- After getting permission, when granted, ask for location via: locator.StartListeningAsync or check if enabled via: !_crossGeolocatorService.IsGeolocationEnabled
Expected Behavior
!_crossGeolocatorService.IsGeolocationEnabled should be true and StartListeningasync should listen for changes.
Actual Behavior
Not listening for location changes and StartListening is not receiving location updates
Code snippet
` Position position = null;
var status = await Permissions.CheckStatusAsync<Permissions.LocationAlways>();
if (status != PermissionStatus.Granted)
{
status = await Permissions.RequestAsync<Permissions.LocationAlways>();
}
if (status == PermissionStatus.Granted)
{
_crossGeolocatorService.DesiredAccuracy = Config.DesiredGeolocationAccuracy;
position = await _crossGeolocatorService.GetLastKnownLocationAsync();
if (position != null)
{
return position;
}
if (!_crossGeolocatorService.IsGeolocationEnabled)
{
return null;
}
position = await _crossGeolocatorService.GetPositionAsync(TimeSpan.FromSeconds(20), null, true);
}
return position;`
And for listening to changes: ` if (_crossGeolocatorService.IsListening) { return; }
_crossGeolocatorService.DesiredAccuracy = 1;
_crossGeolocatorService.PositionChanged += PositionChanged;
var result = await _crossGeolocatorService.StartListeningAsync(TimeSpan.FromSeconds(5), 1, false, new ListenerSettings
{
ActivityType = ActivityType.Other,
AllowBackgroundUpdates = true,
DeferLocationUpdates = false,
DeferralDistanceMeters = 1,
DeferralTime = TimeSpan.FromSeconds(1),
ListenForSignificantChanges = false,
PauseLocationUpdatesAutomatically = false
});`
Screenshotst
I cant get the position when asking it explicitly and I listening to position changes never goes in the "PositionChanged" method, when turning on GPS, it works though... Before I try to both actions, I explicitly ask for permission and when it's granted I try to do the actions... It's just not working. (I tried using xamarin.essentials permission and I also tried the permission library from jamesmontemagno). The IsGeolocatorEnabled returns always false but the permission library returns granted when the user gives permission, so it should return true right...