Fix issue #1574: Add location accuracy filter to prevent GPS drift
Description
This PR addresses issue #1574 by implementing a location accuracy filter to prevent random GPS drift which can cause erratic movement patterns in tracking applications.
Changes
- Added
LocationAccuracyFilterclass to filter out location updates with physically implausible movement patterns - Implemented filtering based on accuracy, speed, and distance thresholds
- Added
enableAccuracyFilterparameter toAndroidSettingsclass - Added unit tests for different transportation modes and edge cases
- Updated documentation and CHANGELOG.md
Implementation Details
The filter works by:
- Detecting locations with very poor accuracy (> 300 meters)
- Filtering unrealistically high speeds (> 280 m/s or ~1000 km/h)
- Identifying large position jumps when combined with poor accuracy values
- Providing a configurable approach that doesn't interfere with legitimate use cases
Testing
The implementation includes comprehensive tests for:
- Standard walking/driving scenarios (accepted)
- High-speed transportation like trains (accepted)
- Unrealistic movements like teleportation (rejected)
- Different accuracy values and edge cases
This solution is designed to be minimally invasive, with filtering disabled by default to maintain backward compatibility.
Dear @Ahmed-Makled,
This looks very nice. However, this functionality should in our opinion not be the responsibility of the geolocator package. Unfortunately it is also not part of the iOS package. You can always filter out the inaccurate locations by listening to the positionStream and filter out unwanted locations.
Kind regards,