Closed nvamsi214 closed 4 years ago
Show me your code you’re using to insert location to Firebase. I see you’re not using the plugin #url.
bg.BackgroundGeolocation.onLocation((bg.Location location) {
saveOldDetails(location.odometer);
String oid = location.extras.containsKey("oid") ? location.extras["oid"] : null;
String uid = location.extras.containsKey("uid") ? location.extras["uid"] : null;
if(/*(location.activity.type != 'still') &&*/ location.coords.accuracy < 50) {
Map<String, dynamic> userTrack = new Map();
userTrack["UID"] = uid;
userTrack["OID"] = oid;
userTrack["latlng"] = GeoPoint(location.coords.latitude, location.coords.longitude);
userTrack["accuracy"] = location.coords.accuracy;
userTrack["otherData"] = location.toMap();
userTrack["event"] = "locationChange";
final collRef = Firestore.instance.collection('orgs').document(OID)
.collection("locs");
DocumentReference docReferance = collRef.document(UID)
.collection("xyzzz")
.document();
var batch = Firestore.instance.batch();
batch.setData(docReferance, userTrack);
batch.commit();
}
});
We are not using the URL plugin.
You’re not interested in the plugin’s Firebase adapter?
We have some issue in using Firebase Adapter while updating the locations to particular path. And also we don't want to rely on cloud functions.
What’s wrong with Firebase functions? They’re not expensive since they don’t involve Network requests in this case (simply remodeling data). It’s like $7.50 for 28M invocations.
See docs: BackgroundGeolocation.startBackgroundTask. Put your Firebase within that.
bg.BackgroundGeolocation.startBackgroundTask().then((va){
String oid = location.extras.containsKey("oid") ? location.extras["oid"] : null;
String uid = location.extras.containsKey("uid") ? location.extras["uid"] : null;
if(location.coords.accuracy < 50) {
Map<String, dynamic> userTrack = new Map();
userTrack["UID"] = uid;
userTrack["OID"] = oid;
userTrack["latlng"] = GeoPoint(location.coords.latitude, location.coords.longitude);
userTrack["accuracy"] = location.coords.accuracy;
userTrack["otherData"] = location.toMap();
userTrack["event"] = "locationChange";
final collRef = Firestore.instance.collection('orgs').document(OID)
.collection("locs");
DocumentReference docReferance = collRef.document(UID)
.collection("xyzzz")
.document();
var batch = Firestore.instance.batch();
batch.setData(docReferance, userTrack);
batch.commit();
}
});
Should we send locations this way?
Is there any other issue in above logs for not sending locations to firebase. Because this is not happening every time. Its happening very randomly few time.
Please use syntax highlighting. you surround your code with 3 backticks + optional language:
bool foo = false;
Should we send locations this way?
Read the docs again and pay close attention to what it says about calling the #finish
method.
Yes, calling StopBackgroundTask() with the task ID after updating data to firebase.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.
Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.
Your Environment
flutter doctor
):Channel stable, v1.7.8+hotfix.4, on Linux, locale en_IN;Expected Behaviour
Service should be running in background (app in background / terminated) and after getting event call back for new location (on Location change or on Motion change), the new location should be sent to Firebase.
Actual Behaviour
Service is running in background and all the new locations are getting recorded in logs too (Debug mode). But the data is not updating in firebase. This is a random behaviour happened thrice for this user in last 1 week. The same user's data is perfectly updated for today again with no changes.
Steps to Reproduce
Context
Update locations to firebase when there is a Motion/Location Change and on Heart Beat to track the user movement. Background service should run in all cases (app in background or terminated).
Debug logs
Logs
``` Debug Logs : [locations.txt](https://github.com/transistorsoft/flutter_background_geolocation/files/3738755/locations.txt) ```