jamesmontemagno / GeolocatorPlugin

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

Speed not always returned for iOS #264

Closed mjorrens closed 6 years ago

mjorrens commented 6 years ago

Bug Information

Version Number of Plugin: 4.5.0.6 Device Tested On: iPhone 6S with OS 11.4 Simulator Tested On: Version of VS: 2017 For PC Version of Xamarin: 3.0.0.550 Versions of other things you are using:

Steps to reproduce the Behavior

Now try this:

Expected Behavior_

The speed should appear as it always does on Android.

Actual Behavior

There seems to be an initial condition problem here. If you call

locator.DesiredAccuracy = DesiredAccuracy.Value; var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(Timeout.Value), null, IncludeHeading.IsToggled);

First with the accuracy at 10meters and THEN listen via StartListeningAsync() all works fine and you get the speed.

I did try to set the DesiredAccuracy before for the StartListeningAsync at 10meters but that did not work which makes me believe that GetPositionAsync sets some initial condition properly.

Code snippet

Screenshots

mjorrens commented 6 years ago

The fix:

Set the DesiredAccuracy: CrossGeolocator.Current.DesiredAccuracy = DesiredAccuracy.Value;

Before calling the listener: if (await CrossGeolocator.Current.StartListeningAsync(TimeSpan.FromSeconds(TrackTimeout.Value), TrackDistance.Value, ...

This is in ButtonTrack_Clicked()

I misspoke in my comment above about trying this and it not working...it does correct the problem. Note the accuracy needs to be 10 meters for the speed to appear properly.

jamesmontemagno commented 6 years ago

I return what apple returns and nothing else I can do.

mjorrens commented 6 years ago

Agreed. Perhaps you update the sample code though with my change above so other folks don't get the problem.

Thanks.