Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IsGeolocationEnabled always returns false #324

Open
programmingworld1 opened this issue May 27, 2020 · 1 comment
Open

IsGeolocationEnabled always returns false #324

programmingworld1 opened this issue May 27, 2020 · 1 comment

Comments

@programmingworld1
Copy link

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

@programmingworld1
Copy link
Author

programmingworld1 commented May 27, 2020

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant