transistorsoft/flutter_background_geolocation

Optimize Location Retrieval Frequency: Differentiate Foreground and Background Modes to Save Battery

Opened this issue · 8 comments

@christocracy

Your Environment

  • Plugin version: ^4.16.0
  • Platform: iOS and Android
  • OS version: Sequoia 15.1.1
  • Device manufacturer / model: MacBook Pro M3 Pro
  • Flutter info (flutter doctor):
  • Plugin config:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.4, on macOS 15.1.1 24B91 darwin-arm64, locale en-FR)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] VS Code (version 1.95.3)
[✓] Connected device (5 available)
[✓] Network resources

• No issues found!

Expected Behavior + Context

I integrated the lib into my application and it works well.
I retrieve the location in the foreground more often because I move a point on a map. The problem is that I do not save the location in db each time I retrieve it (I store it every 150m / 200m).

So when the application is in the background I also retrieve the location very often while I do not move a point on my map. So I retrieve these locations for nothing.

I would like to know if there is a way for the lib to retrieve more often in the foreground than in the background? This would drastically reduce battery consumption because my application is more often in the background than in the foreground.

While in the foreground, initiate a Timer and call .getCurrentPosition. See the api docs for this method — one of the options you can provide to that method is persist: false, meaning it will not be inserted into the sdk’s sqlite db, thus never appear in http requests.

@christocracy
It's good solution in the short term. The problem with this solution is that I lose the battery efficiency in the foreground, which is the purpose of the library. Is there a way to create 2 singleton classes with 2 library integrations? will switching between the two have a detrimental effect?

that I lose the battery efficiency in the foreground

Why do you think that? It’s not true.

While in the foreground, the energy draw of calling .getCurrentPosition pales in comparison to the energy drain of the screen being on.

Ok i didn't know that. So the best way is :

Foreground -> set timer to get current position (.getCurrentPosition)
Background -> Use the lib distance filter when the init the lib

if it's right i'll implement that.

@christocracy
Do you know how can we benchmark the batterie consumption to understand it ?

Do you know how can we benchmark the batterie

No.

you don’t need to worry about this.

This issue is stale because it has been open for 30 days with no activity.