-
Notifications
You must be signed in to change notification settings - Fork 7
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
Throttle the Frequency of Location Updates to Firebase #9
Comments
There is no way to handle this currently. It would not be implemented in the Firebase adapter, it would should be implemented in |
You could manually manage this via BackgroundGeolocation#setConfig with Config.maxRecordsToPersist, oscillating between setting that to 0 and -1 with your own logic. |
Chris, In my // handle throttling updates to Firebase
if (liveFireStoreEnabled) {
DateTime now = DateTime.now();
if(now.isAfter(lastUpdateToFirebase.add(Duration(seconds: liveFireStoreInterval ))))
{
bg.BackgroundGeolocation.setConfig(bg.Config(maxRecordsToPersist: -1)); // no limit - store point(s) to SQL and Firebase
lastUpdateToFirebase = now;
print('&&&&&&&&&Firestore Insert ON &&&&&&&&&&');
} else {
bg.BackgroundGeolocation.setConfig(bg.Config(maxRecordsToPersist: 0)); // don't store this point
print('&&&&&&&&&Firestore Insert OFF &&&&&&&&&&');
}
} But see the attached log, which seems to show:
Testing on a real Android device indicates I am still getting all locations sent to Firebase. Your insights would be appreciated. |
Set it 0 and keep it 0. You’ll find nothing gets persisted. |
But if I do that, won't I get no locations sent to Firebase? I still want a location sent every 10 seconds. |
I’m asking you to do a test, to perform an extreme case and determine the outcome. |
OK - Sorry - my misunderstanding. I have set both branches of the if statement to: All locations are still being sent to Firebase...! |
You needn’t provide exclamations (!). Just provide the facts and I’ll look into it. |
OK not meaning to imply anything. Just is case it's relevant, in my initial bgConfigToApply = bg.Config(
persistMode: saveToBGsqlDBandLiveTrack,
..... where int saveToBGsqlDBandLiveTrack = liveFireStoreEnabled
? bg.Config.PERSIST_MODE_ALL
: bg.Config.PERSIST_MODE_NONE; |
Chris, I've changed my manual throttling of location updates to Cloud Firestore, to the following. // handle throttling updates to Firebase
if (liveFireStoreEnabled) {
DateTime now = DateTime.now();
if(now.isAfter(lastUpdateToFirebase.add(Duration(seconds: liveFireStoreInterval ))))
{
bg.BackgroundGeolocation.setConfig(bg.Config(persistMode: bg.Config.PERSIST_MODE_ALL)); // store point(s) to SQL and Firebase
lastUpdateToFirebase = now;
print('&&&&&&&&&Firestore Insert ON &&&&&&&&&&');
} else {
bg.BackgroundGeolocation.setConfig(bg.Config(persistMode: bg.Config.PERSIST_MODE_NONE)); // don't store to SQL/Firebase
print('&&&&&&&&&Firestore Insert OFF &&&&&&&&&&');
}
} Testing so far indicates that this is working. That is:
My questions is:
Thanks |
Chris, |
Yes, but I won’t be able to get around to starting on this this for at least a month. |
OK - thanks - no problems - I'll look forward to it in due course. |
Chris, |
Chris, Context: My MapRunF App is being used by runners for 8,000-10,000 runs per month. Some organising clubs would like live tracking...but if I push all data to Firebase, I get too much data. With my current approach to culling the data (as above), I lose data if there is no data connection. I guess I could revert to sending all data from the App to Firebase and then culling it there with a Firebase Function ... but I could incur higher usage charges from Google. |
What's wrong with the solution you posted above using persistMode? |
Chris, I'm pretty sure that when I do: any data queued up in the internal SQL database (that hasn't been sent to Firebase) will be discarded. This is OK if the device is always online (as I assume lost data would be minimal), but for the types of events we run, that can't be assumed. Peter |
When you activate the Firebase Adapter, persistence to background-geolocation's SQLite database is disabled. Firebase automatically handles on-device queuing of data when there's no network connection. |
Thanks - Looks like I have made incorrect assumptions, and so my current approach of throttling updates to Firebase may well be adequate. I'll do some more thorough testing. |
@christocracy Any update on this? I am looking for the same behavior of sending location into the database with an interval of not less than 20 minutes. Setting persistMode approach is ok? |
You are free to switch that |
Chris,
My app needs frequent location updates to perform its functions, but I only need less frequent location updates to Firebase.
Would you consider adding a parameter such as:
such that a location update would not be sent to firebase if a previous location had been sent within firebase_update_interval seconds.
I would continue to take location updates as quickly as they are available, but set this to parameter somewhere in the range 10 to 60 seconds.
Alternatively is there a way I can intercept updates to firebase myself to achieve this?
Peter
The text was updated successfully, but these errors were encountered: