jamesmontemagno / GeolocatorPlugin

Geolocation plugin for Xamarin and Windows
MIT License
294 stars 158 forks source link

IsGeolocationEnabled always returns false #324

Open programmingworld1 opened 4 years ago

programmingworld1 commented 4 years ago

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

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 commented 4 years ago

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