Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
KatnissApp opened this issue Nov 22, 2024 · 7 comments

Comments

@KatnissApp
Copy link

KatnissApp commented Nov 22, 2024

@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.

@christocracy
Copy link
Member

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.

@YaLazreq
Copy link

@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?

@christocracy
Copy link
Member

that I lose the battery efficiency in the foreground

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

@christocracy
Copy link
Member

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

@YaLazreq
Copy link

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.

@YaLazreq
Copy link

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

@christocracy
Copy link
Member

Do you know how can we benchmark the batterie

No.

you don’t need to worry about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants