flutter-geolocator icon indicating copy to clipboard operation
flutter-geolocator copied to clipboard

Inaccurate Location Tracking: Randomly Drifting GPS Points

Open Gonn01 opened this issue 1 year ago • 16 comments

Please check the following before submitting a new issue.

Please select for which platform(s) you need help

  • [X] Android
  • [ ] iOS
  • [ ] Linux
  • [ ] macOS
  • [ ] Web
  • [ ] Windows

Your question

I'm developing a Flutter application to track the user's location every 30 seconds and generate a route.

I've encountered an issue where the package occasionally records GPS coordinates that are significantly far from the device's actual location, causing unexpected deviations in the generated route. These inaccurate readings seem to occur randomly and then correct themselves after a short period.

  final LocationSettings locationSettings = AndroidSettings(     
    intervalDuration: const Duration(seconds: 30),
    accuracy: LocationAccuracy.bestForNavigation,
    foregroundNotificationConfig: const ForegroundNotificationConfig(
      // Explain to the user why we are showing this notification.
      notificationText:
          'App will continue to receive your location even when you arent'
          ' using it',
      // Tell the user what we are doing.
      notificationTitle: 'Running in Background', 
      // Give the notification an amber color.
      color: Colors.amber, setOngoing: true,
    ),
  );
  Geolocator.getPositionStream(locationSettings: locationSettings).listen(
    (Position position) async {
      await BackGpsRepository().checkAndSend(position);
    },
  );

Expected Behavior: The package should consistently provide accurate GPS coordinates, allowing for the generation of a smooth and realistic route.

Actual Behavior: The package intermittently records GPS coordinates that are significantly off, resulting in a distorted route with unexpected jumps.

Additional Information:

Package Version: 13.0.1 Flutter Version: 3.22.3 Affected Devices: g54 Motorola Operating Systems: Android Permissions in AndroidManifest:

In this case i stay on the same position and randomly throw a position far away and comeback later. Screenshot_20240920-131135 (1)

Version

13.0.1

Gonn01 avatar Sep 20 '24 16:09 Gonn01

Please check the following before submitting a new issue.

Please select for which platform(s) you need help

  • [x] Android
  • [ ] iOS
  • [ ] Linux
  • [ ] macOS
  • [ ] Web
  • [ ] Windows

Your question

I'm developing a Flutter application to track the user's location every 30 seconds and generate a route.

I've encountered an issue where the package occasionally records GPS coordinates that are significantly far from the device's actual location, causing unexpected deviations in the generated route. These inaccurate readings seem to occur randomly and then correct themselves after a short period.

  final LocationSettings locationSettings = AndroidSettings(     
    intervalDuration: const Duration(seconds: 30),
    accuracy: LocationAccuracy.bestForNavigation,
    foregroundNotificationConfig: const ForegroundNotificationConfig(
      // Explain to the user why we are showing this notification.
      notificationText:
          'App will continue to receive your location even when you arent'
          ' using it',
      // Tell the user what we are doing.
      notificationTitle: 'Running in Background', 
      // Give the notification an amber color.
      color: Colors.amber, setOngoing: true,
    ),
  );
  Geolocator.getPositionStream(locationSettings: locationSettings).listen(
    (Position position) async {
      await BackGpsRepository().checkAndSend(position);
    },
  );

Expected Behavior: The package should consistently provide accurate GPS coordinates, allowing for the generation of a smooth and realistic route.

Actual Behavior: The package intermittently records GPS coordinates that are significantly off, resulting in a distorted route with unexpected jumps.

Additional Information:

Package Version: 13.0.1 Flutter Version: 3.22.3 Affected Devices: g54 Motorola Operating Systems: Android Permissions in AndroidManifest:

In this case i stay on the same position and randomly throw a position far away and comeback later. Screenshot_20240920-131135 (1)

Version

13.0.1

Any answers? To solve it , I got the same issue

abdull-rahmann avatar Oct 08 '24 05:10 abdull-rahmann

Please check the following before submitting a new issue.

Please select for which platform(s) you need help

  • [x] Android
  • [ ] iOS
  • [ ] Linux
  • [ ] macOS
  • [ ] Web
  • [ ] Windows

Your question

I'm developing a Flutter application to track the user's location every 30 seconds and generate a route. I've encountered an issue where the package occasionally records GPS coordinates that are significantly far from the device's actual location, causing unexpected deviations in the generated route. These inaccurate readings seem to occur randomly and then correct themselves after a short period.

  final LocationSettings locationSettings = AndroidSettings(     
    intervalDuration: const Duration(seconds: 30),
    accuracy: LocationAccuracy.bestForNavigation,
    foregroundNotificationConfig: const ForegroundNotificationConfig(
      // Explain to the user why we are showing this notification.
      notificationText:
          'App will continue to receive your location even when you arent'
          ' using it',
      // Tell the user what we are doing.
      notificationTitle: 'Running in Background', 
      // Give the notification an amber color.
      color: Colors.amber, setOngoing: true,
    ),
  );
  Geolocator.getPositionStream(locationSettings: locationSettings).listen(
    (Position position) async {
      await BackGpsRepository().checkAndSend(position);
    },
  );

Expected Behavior: The package should consistently provide accurate GPS coordinates, allowing for the generation of a smooth and realistic route. Actual Behavior: The package intermittently records GPS coordinates that are significantly off, resulting in a distorted route with unexpected jumps. Additional Information: Package Version: 13.0.1 Flutter Version: 3.22.3 Affected Devices: g54 Motorola Operating Systems: Android Permissions in AndroidManifest: In this case i stay on the same position and randomly throw a position far away and comeback later. Screenshot_20240920-131135 (1)

Version

13.0.1

Any answers? To solve it , I got the same issue

I think is something with the battery optimization of the device but im not sure

Gonn01 avatar Oct 08 '24 14:10 Gonn01

Any answers? To solve it, the same issue occurred in my application while using map navigation.

GohelBrijesh avatar Oct 11 '24 09:10 GohelBrijesh

I got same issue, plz help

NhaPCS avatar Oct 11 '24 09:10 NhaPCS

are you guys also using mapbox?

NhaPCS avatar Oct 11 '24 10:10 NhaPCS

are you guys also using mapbox?

Yes ,

hussenIbrahim avatar Oct 13 '24 06:10 hussenIbrahim

common guys, is there any super hero to solve this?

USardorB avatar Dec 09 '24 13:12 USardorB

you should creating your own algorithm that uses the previous, current, and incoming GPS points (latitude and longitude) to reduce GPS drifting. It works by analyzing movement patterns between these points and detecting unrealistic jumps or sharp changes in direction or speed.

The idea is to filter out sudden spikes caused by weak GPS signals—like when you’re standing still but your location keeps jumping around. The algorithm checks the distance, speed, and angle between points. If something seems off like that big jump that doesn’t make sense, it ignores will not put it in polylines.

jesther-ai avatar Apr 15 '25 07:04 jesther-ai

Actually, it turns out, it's pretty simple than one might think. You just need to skip the lower accuracy gps data, and that's it. It took me weeks to realize this. If you're gonna draw with that info to map, you can use kalvin(I'm not sure if this is a correct spelling) formula for GPS. You can create one with GPT

USardorB avatar Apr 15 '25 07:04 USardorB

Any answers? To solve it, the same issue occurred in my application while using map navigation.

Ahmed-Makled avatar May 14 '25 18:05 Ahmed-Makled

How do you define what is low accuracy? 2 meters? Or you let the user configure that?

steinmetz avatar May 17 '25 06:05 steinmetz

How do you define what is low accuracy? 2 meters? Or you let the user configure that?

The Position object includes an accuracy in meters—use this to create a condition that disqualifies any newly emitted object if the accuracy isn’t sufficient.

jesther-ai avatar May 17 '25 07:05 jesther-ai

Dear @Gonn01 and other members of this thread,

This happens because the Android OS uses several other sensors like WIFI or Cellular connections to determine your location. If it is "unable" to fetch a location (for example) via GPS (or for efficiency reasons) it could be possible that the OS determines a location via a wifi point. The location of this wifi point could be inaccurate, however it could also be the "best possible" option when you are for example indoors. By setting the forceLocationManager: true in the AndroidSettings, you basically force the OS to use the old location manager that uses the GPS. That way it could be possible to fetch more accurate locations... HOWEVER, indoor you could have some issues on determining the location when you use GPS. So I would suggest trying this to see if it improves (outside).

Kind regards,

TimHoogstrate avatar May 20 '25 11:05 TimHoogstrate

I am also having this issue in outdoors.

Image

I updated my code to add a filter based on the accuracy as mentioned here in this thread, but I have no feedbacks from my users yet if it worked or not.

One user who reported that was using an iPhone 15.

steinmetz avatar May 20 '25 11:05 steinmetz

@steinmetz,

What would you expect? Try to set the accuracy to .best and forceLocationManager: true. Phone with open sky, batteries charged. That would be the best possible location you can determine by gps with an on board gps chip. It looks like something is happening externally when the locations start to become inaccurate.

Kind regards,

TimHoogstrate avatar Jun 04 '25 11:06 TimHoogstrate

Hi @TimHoogstrate

Hope you are doing well.

Please find attached video it's a real world use case where a driver is moving from Qatri Brothers building to Hamad international Airport the total distance is 9.6 KM but it turned 19 Km because there are some points that are fired randomly. it's not a single case i've lot more.

https://drive.google.com/file/d/1MBRSj5WXmMGxgtssh9INLTe0z1Vu3dr9/view?usp=sharing

OsamaQureshi796 avatar Jun 04 '25 11:06 OsamaQureshi796

Actually, it turns out, it's pretty simple than one might think. You just need to skip the lower accuracy gps data, and that's it. It took me weeks to realize this. If you're gonna draw with that info to map, you can use kalvin(I'm not sure if this is a correct spelling) formula for GPS. You can create one with GPT

Does it return low accuracy data in getPositionStream even we set accuracy to high & best ?

qky1412 avatar Aug 29 '25 01:08 qky1412

Hi @TimHoogstrate

Hope you are doing well.

Please find attached video it's a real world use case where a driver is moving from Qatri Brothers building to Hamad international Airport the total distance is 9.6 KM but it turned 19 Km because there are some points that are fired randomly. it's not a single case i've lot more.

https://drive.google.com/file/d/1MBRSj5WXmMGxgtssh9INLTe0z1Vu3dr9/view?usp=sharing

Hi there, when using the [location updates stream], filter it like this: [location updates stream].where((e)=>//set accuracy filter just like this, to your liking). And your problem is solved. Also you can make the updates a bit more frequent, as the filter above will skip some updates. I have been in your situation, and this is what I learnt. The interesting thing is, there is no well known tutorial for this way of fixing the problem. @steinmetz @qky1412 @TimHoogstrate @NhaPCS @Ahmed-Makled

USardorB avatar Sep 05 '25 00:09 USardorB