mauron85 / cordova-plugin-background-geolocation

Background and foreground geolocation plugin for Cordova.
Apache License 2.0
537 stars 406 forks source link

Interval not working as set #275

Closed mcichecki closed 6 years ago

mcichecki commented 7 years ago

Your Environment

  timePeriod: number = 10;
  ms : number = 60000;
...

  let config = {
    stationaryRadius: 50, 
    distanceFilter: 50, 
    desiredAccuracy: 10, 
    debug: true,
    locationProvider: 1,
    interval: this.timePeriod * this.ms, 
    fastestInterval: 5,
    activitiesInterval: 10,
    stopOnTerminate: false,
    startForeground: true,
    stopOnStillActivity: false,
    activityType: 'AutomotiveNavigation',
    url: 'http://192.168.0.18:8080',
    syncThreshold: 100,
    httpHeaders: { //Optional HTTP headers sent along in HTTP request
    'X-FOO': 'bar' 
    },
    pauseLocationUpdates: false,
    saveBatteryOnBackground: false,
    maxLocations: 100
  };

Expected Behavior

I've got Range from Ionic components which changes the value of time interval: interval: interval: this.timePeriod * this.ms If interval is in miliseconds then 1 60000 should be 1min and 5 60000 = 300000 should be 5 min.

Actual Behavior

I've set a simple server and could see that time period is not always equal. 1 6000 = data were appearing in every 2-4 seconds 5 6000 =

lat: XXXXXX lng: XXXXXX time: Fri Mar 17 2017 19:57:46 GMT+0100 (CET)
lat: XXXXXX lng: XXXXXX time: Fri Mar 17 2017 19:58:16 GMT+0100 (CET)
lat: XXXXXX lng: XXXXXX time: Fri Mar 17 2017 19:58:22 GMT+0100 (CET)
lat: XXXXXX lng: XXXXXX time: Fri Mar 17 2017 19:58:46 GMT+0100 (CET)

As you can see I've set 6000ms which is 6 seconds. 5 6 seconds = 30 seconds So it's more or less ok. But for 106000 which is one minute data were coming every ~35s:

lat: XXXXXX lng: XXXXXX time: Fri Mar 17 2017 20:01:22 GMT+0100 (CET)
lat: XXXXXX lng: XXXXXX time: Fri Mar 17 2017 20:01:46 GMT+0100 (CET)
lat: XXXXXX lng: XXXXXX time: Fri Mar 17 2017 20:02:22 GMT+0100 (CET)
lat: XXXXXX lng: XXXXXX time: Fri Mar 17 2017 20:02:58 GMT+0100 (CET)
lat: XXXXXX lng: XXXXXX time: Fri Mar 17 2017 20:03:22 GMT+0100 (CET)
lat: XXXXXX lng: XXXXXX time: Fri Mar 17 2017 20:03:58 GMT+0100 (CET)
lat: XXXXXX lng: XXXXXX time: Fri Mar 17 2017 20:04:22 GMT+0100 (CET)

So how can I define the range slider to be able to set interval for 5, 10, 15... minutes and the apply it to the app to get correct interval period?

Context

I'm trying to get range slider where user can set interval (5min, 10min and so on) and get data on the server every set period of time.

MaximilienFaure commented 7 years ago

I have exactly the same problem. When I set the interval option to 60000ms (one minute), I get : 06-06 14:10:43 06-06 14:11:32 06-06 14:12:11 06-06 14:14:58 06-06 14:16:03 06-06 14:16:34 06-06 14:16:37 Have you find a solution for this issue ?

regards, Max

mcichecki commented 7 years ago

@MaximilienFaure Yes. It should work fine:

      updateInterval = 60000; //60000ms = 1min
      timePeriod: number = 1;

      interval: this.updateInterval * this.timePeriod,
      fastestInterval: this.updateInterval * this.timePeriod,
      activitiesInterval: this.updateInterval * this.timePeriod,
MaximilienFaure commented 7 years ago

Thanks for your answer, but I tried agin and that doesn't work. even if my configuration is like that : backgroundGeolocation.configure(callbackEnregistrementBackground, failureFn, { desiredAccuracy: backgroundGeolocation.accuracy.MEDIUM, stationaryRadius: 15, distanceFilter: 15, interval: 60000 //1min }); backgroundGeolocation.start();

I get this output :

06-06 15:44:47.697 06-06 15:47:50.473 06-06 15:51:11.474 06-06 15:51:11.495 06-06 15:51:46.470 06-06 15:56:50.749 06-06 16:01:51.584 06-06 16:02:32.660 06-06 16:03:25.457

So what is the accurate of interval ? about 1 minute ? 2 minutes ? 10 ?

ps : fastestInterval and activitiesInterval are just for android, no ?

Regards, Max

mauron85 commented 6 years ago

Notice: this issue has been closed because it has been reported for branch 2.x or later. It could be already fixed in v3 or is not relevant anymore. You may reopen this issue if it has been closed in error.