jamesmontemagno / GeolocatorPlugin

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

Generates many events when deployed to phone #332

Closed jammerx19 closed 3 years ago

jammerx19 commented 4 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

Version Number of Plugin: 4.5.0.6 Device Tested On: iPhone XS Max Simulator Tested On: iOS simulator, VS 2019 Version of VS: 2019 Version of Xamarin: 4.6.0.1141 Versions of other things you are using:

Steps to reproduce the Behavior

  1. Deploy app to iPhone through the Mac via Visual Studio.
  2. While the app is running, move the phone through the air about three inches and the phone will generate 20-60 location changed events instantly.

Expected Behavior

Expect no real change events in this situation

Actual Behavior

Generates many calls to my PositionChanged event handler when the phone moves a tiny amount in my hand.

Code snippet

            await CrossGeolocator.Current.StartListeningAsync(TimeSpan.FromMinutes(3), 100, true, new Plugin.Geolocator.Abstractions.ListenerSettings
            {
                ActivityType = Plugin.Geolocator.Abstractions.ActivityType.AutomotiveNavigation,
                AllowBackgroundUpdates = true,
                DeferLocationUpdates = false,
                ListenForSignificantChanges = true,
                PauseLocationUpdatesAutomatically = false
            });

            CrossGeolocator.Current.PositionChanged += PositionHasChanged;

Screenshotst

TheWatchfulOne commented 3 years ago

I think it's because, currently, the CLLocationManager inputs an array of CLLocation objects to its delegate method. According the Apple's documentation, the most recent location is the last one in the array. The Geolocator plugin iterates thought that array and fires the PositionChanged event for every location in it. I think it should only fire the event for the last location in the array. I'll try to submit a PR unless somebody beats me to it.

bizyyosh commented 3 years ago

I am experiencing the same problem. Does anyone have any good information about this problem?

TheWatchfulOne commented 3 years ago

I have submitted a pull request but it has not been reviewed yet. Hopefully I did it correctly.

jammerx19 commented 3 years ago

Would be nice if it got fixed, but I've since abandoned the approach and the plugin entirely and headed in a different direction.