transistorsoft / flutter_background_geolocation

Sophisticated, battery-conscious background-geolocation & geofencing with motion-detection
https://www.transistorsoft.com/shop/products/flutter-background-geolocation
Other
640 stars 237 forks source link

Unable to send data to server even though getting all locations in logs. #133

Closed nvamsi214 closed 4 years ago

nvamsi214 commented 4 years ago

Your Environment

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

  1. Random behaviour. One of observed situation is that the user was travelling while punching in (initiating the background service).

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) ```
christocracy commented 4 years ago

Show me your code you’re using to insert location to Firebase. I see you’re not using the plugin #url.

nvamsi214 commented 4 years ago
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();
    }
  });
nvamsi214 commented 4 years ago

We are not using the URL plugin.

christocracy commented 4 years ago

You’re not interested in the plugin’s Firebase adapter?

nvamsi214 commented 4 years ago

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.

christocracy commented 4 years ago

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.

christocracy commented 4 years ago

See docs: BackgroundGeolocation.startBackgroundTask. Put your Firebase within that.

nvamsi214 commented 4 years ago
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();
        }
      });
nvamsi214 commented 4 years ago

Should we send locations this way?

nvamsi214 commented 4 years ago

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.

christocracy commented 4 years ago

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.

nvamsi214 commented 4 years ago

Yes, calling StopBackgroundTask() with the task ID after updating data to firebase.

stale[bot] commented 4 years ago

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.

stale[bot] commented 4 years ago

Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.