transistorsoft / cordova-background-geolocation-lt

The most sophisticated background location-tracking & geofencing module with battery-conscious motion-detection intelligence for iOS and Android.
http://www.transistorsoft.com/shop/products/cordova-background-geolocation
Other
655 stars 277 forks source link

"locationTemplate" not being applied #1042

Closed dmitry-stepanenko closed 4 years ago

dmitry-stepanenko commented 4 years ago

Your Environment


BackgroundGeolocation.ready({
      reset: true,
      debug: true,
      logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
      desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
      distanceFilter: 10,
      method: 'POST',
      url: 'htpps://mock',
      headers: {
        Authorization: 'Bearer mock',
      },
      locationTemplate: '{"Lat": <%= latitude %>, "Lng": <%= longitude %>}',
      autoSync: true,
      stopOnTerminate: false,
      startOnBoot: true
    }, (state) => {
      console.log('[ready] BackgroundGeolocation is ready to use');
      if (!state.enabled) {
        // 3.  Start tracking.
        BackgroundGeolocation.start();
      }
    });

Please note, that actual endpoint and authorization are being removed from an example. When tested, I used real endpoint.

Expected Behavior

Location template should be applied within a configuration.

Actual Behavior

I am providing location template in a configuration as follows: locationTemplate: '{"Lat": <%= latitude %>, "Lng": <%= longitude %>}',

Using android profilier I've checked the payload that is being sent and it's as follows:

{
  "location": {
    "latitude": 37.2785317,
    "longitude": -122.2003717
  }
}

Steps to Reproduce

Created a blank ionic capacitor application to reproduce. Please, take a look https://github.com/cuddlemeister/bug-reproduction-cordova-background-geolocation-lt

christocracy commented 4 years ago

BackgroundGeolocation.destroyLocations()

The plugin has queued records encoded with previous or default template. It keeps attempting to upload those old records and your server keeps returning non-200 response. The plugin is going to keep trying until you either:

  1. Delete records in the plugin's queue with destroyLocations
  2. Your server return http 200
dmitry-stepanenko commented 4 years ago

I've done what you said and now the payload looks like this:

{
  "location": {
    "Lat": 37.2600333,
    "Lng": -122.1017383
  }
}

Is it possible to make Lat \ Lng properties in the root of the object?

christocracy commented 4 years ago

The answer is in the api docs. Search for “rootProperty”

himanshu849 commented 4 years ago

you can use this property ( httpRootProperty: '.' ) to get data in root. thanks

dmitry-stepanenko commented 4 years ago

you can use this property ( httpRootProperty: '.' ) to get data in root. thanks

yes, I've already used this and it did the trick. thanks

ptv1p3r commented 4 years ago

How can i check the format the payload is beeing sent in android studio ?

christocracy commented 4 years ago

You can’t. Make sure the plugin database doesn’t have old locations rendered with default template via #destroyLocations

ptv1p3r commented 4 years ago

i'm doing : BackgroundGeolocation.start(); BackgroundGeolocation.destroyLocations();

Should this be enough ?

christocracy commented 4 years ago

You should not always be using #destroyLocations each time the app starts.

ptv1p3r commented 4 years ago

These are the configs i'm using:

httpRootProperty: '.', url: appSettings.getString("API_URL") + ":" + appSettings.getString("API_PORT") + "/v1/user/location", locationTemplate: '{ "latitude":<%= latitude %>, "longitude":<%= longitude %> }', autoSync: true, autoSyncThreshold: 5, batchSync: true, maxBatchSize: 50, method: 'POST', headers: { "content-type" : "application/json", "Authorization": widget.currentUser.token, }, locationsOrderDirection: "DESC", maxDaysToPersist: 14,

I would expect the payload to be : { "latitude" : 12.546, "longitude": 64654.323} would it be a correct assumption ?

christocracy commented 4 years ago

Yes

dmitry-stepanenko commented 4 years ago

@ptv1p3r How can i check the format the payload is beeing sent in android studio ?

You can see it in android studio's profiler in network section

christocracy commented 4 years ago

You can see it in android studio's profiler in network section

Oops, sorry. Misunderstood your post. You can? Show me a screenshot of that.

ptv1p3r commented 4 years ago

You can see it in android studio's profiler in network section

Oops, sorry. Misunderstood your post. You can? Show me a screenshot of that.

same.. how can i see it? it would solve a lot of problems here eheh...

ptv1p3r commented 4 years ago

Just found out how :-) TY image

christocracy commented 4 years ago

Oh, that’s neat!

ptv1p3r commented 4 years ago

And i just found out one the problems, it's that not all keys are always present, for instance event ... i thought from the documentation that it would always be present, but it could be empty, that's not the case, if it's empty, the key does not exist...

christocracy commented 4 years ago

Correct. No point inflating the data with an empty-string.

ptv1p3r commented 4 years ago

Yes, but it's not explicit in the documentation and it should.. now the question rises, what other keys have the same behavior ?

ptv1p3r commented 4 years ago

@ptv1p3r How can i check the format the payload is beeing sent in android studio ?

You can see it in android studio's profiler in network section

Thank You !!!!!! You are a life saver !!!!

christocracy commented 4 years ago

See Wiki Location Data Schema

ptv1p3r commented 4 years ago

See Wiki Location Data Schema

So those keys will always be present, and all others may or may not be present depending on content ? is that correct ?

christocracy commented 4 years ago

yes