jamesmontemagno / GeolocatorPlugin

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

Fails to get current location: throws TaskCanceledException error #291

Open abdulkhn8 opened 5 years ago

abdulkhn8 commented 5 years ago

For common questions and issues see the FAQ

If you are creating an issue for a BUG please fill out this information. If you are asking a question or requesting a feature you can delete the sections below.

Failure to fill out this information will result in this issue being closed. If you post a full stack trace in a bug it will be closed, please post it to http://gist.github.com and then post the link here.

Bug Information

Mostly plugin works normally, but sometimes it suddenly stops working and throws TaskCanceledException. I even tried to increase the timeout to 100 but still exception.

it suddenly stops and suddenly starts working. i dont how to debug this scenario.

Version Number of Plugin: 4.5.0.6 Device Tested On: Moto Z Play Version of VS: 7.8 (build 1624) Version of Xamarin: Xamarin.Forms : 3.5.0.129452 Xamarin.Android Version: 9.1.8.0 (Visual Studio Professional) Android SDK: Xamarin/android-sdk-macosx Supported Android versions: 8.1 (API level 27)

SDK Tools Version: 26.1.1 SDK Platform Tools Version: 28.0.1 SDK Build Tools Version: 27.0.3 Versions of other things you are using:

Steps to reproduce the Behavior

Simply get current position anywhere

Expected Behavior

Current position given

Actual Behavior

TaskCanceledException

Code snippet

if (CrossGeolocator.Current.IsGeolocationEnabled)
                    {
                        var position = await CrossGeolocator.Current.GetPositionAsync(TimeSpan.FromSeconds(10));
                        globalInfo.Position = position;
                        if (globalInfo.Position != null)
                        {
                            foreach (var item in DefaultList.Where(x => x.Distance.Equals(0)))
                            {
                                item.Distance = (float)(Math.Round(
                                new Coordinates(globalInfo.Position.Latitude, globalInfo.Position.Longitude).
                                    DistanceTo(new Coordinates(Convert.ToDouble(item.Latitude), Convert.ToDouble(item.Longitude)),
                                                 UnitOfLength.Kilometers)));
                            }
                            UpdateList();
                        }
                    }

Screenshotst

rohitvipin commented 5 years ago

Are you calling the plugin multiple times before previous ones have completed? You can try using semaphore slim to make it invoke in serial and see the issue is present.