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

There is a limit on distanceFilter? #1360

Closed marcob77 closed 1 year ago

marcob77 commented 1 year ago

Your Environment

After user login window.BackgroundGeolocation.setConfig( { method: 'POST',

           // reset: true,
            debug: false,

           logLevel: window.BackgroundGeolocation.LOG_LEVEL_ERROR,
            desiredAccuracy: window.BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
            locationAuthorizationRequest: 'Always',
            distanceFilter: 20000, //20km   
            autoSync: true,
            stopOnTerminate: false,
            startOnBoot: true
        });
    }

on location.. bgGeo.onLocation(function (location) { var sessionIsActive = storage.getItem('sessionIsActive'); let yourDate = new Date(); console.log("onLocation"); window.localStorage.setItem("dataAcquisizione",yourDate.toISOString().split('T')[0]);

    if (location.sample !== true) {
        window.localStorage.setItem("latitude",location.coords.latitude.toString().replace(".",","));
        window.localStorage.setItem("longitude",location.coords.longitude.toString().replace(".",","));

        //####
       var id=window.localStorage.getItem('identificativo');
      //  console.log('executeAfterLocationGeocoding http://employee.geosecuritysystem.local/api/edit/tbl_position/'+id);

        window.BackgroundGeolocation.setConfig(
        {
            disableElasticity:true,
              autoSync: true,
            method: 'POST',
            distanceFilter: 20000 ,//20km

            locationAuthorizationRequest: 'Always',
              stopOnTerminate: false,
            url: indirizzoServer+'/api/edit/tbl_position/'+id+'?g=g',
            params: {"localita":"","countryCode":"","idtbl_position": id, "identificativo": "234i", "latitudine": location.coords.latitude.toString().replace(".",","), "longitudine": location.coords.longitude.toString().replace(".",","), "data_acquisizione": window.localStorage.getItem('dataAcquisizione'), "progetto": "master", "nome": "Marco", "cognome": "Bernardi", "telefono": "33333333333", "email": "berrdi.mco@gmail.com","prefissoInternazionale": null,"luogoNascita": null,"dataNascita": null},
            headers: {'X-Authorization': 'Bearer ' + window.localStorage.getItem('tokenJWT')}

        });
        cordova.plugins.notification.local.schedule({
            title: 'Posizione calcolata',
            text: 'Thats pretty easy...',
            foreground: true
        });

    }

## Expected Behavior
<!--- Tell us what should happen -->
My app would do nothing untile user logged in. After logged, app starts tracking position every 20km and send info to server
## Actual Behavior
<!--- Tell us what happens instead -->
App send  position too often (here an extract from my database). Maybe there is a limit on distanceFilter option? If i use useSignificantChangesOnly options, it works as expected but i need greater range

126|10 | Roma, Roma Capitale, Lazio, Italia | IT | 41.936989567078 | 12.456193169547 | master | F | 2022-08-08 | 2022-08-08 | 2022-08-08 07:50:47
-- | -- | -- | -- | -- | -- | -- | -- | -- | --
  | 127 | 10 | Roma, Roma Capitale, Lazio, Italia | IT | 41.935846267003 | 12.455486855143 | master | F | 2022-08-08 | 2022-08-08 | 2022-08-08 07:50:54
  | 128 | 10 | Roma, Roma Capitale, Lazio, Italia | IT | 41.935846267003 | 12.455486855143 | master | F | 2022-08-08 | 2022-08-08 | 2022-08-08 07:54:29
  | 129 | 10 | Roma, Roma Capitale, Lazio, Italia | IT | 41.937285393554 | 12.457783779498 | master | F | 2022-08-08 | 2022-08-08 | 2022-08-08 07:54:40
  | 130 | 10 | Roma, Roma Capitale, Lazio, Italia | IT | 41.937285393554 | 12.457783779498 | master | F | 2022-08-08 | 2022-08-08 | 2022-08-08 07:55:50
  | 131 | 10 | Roma, Roma Capitale, Lazio, Italia | IT | 41.937285393554 | 12.457783779498 | master | F | 2022-08-08 | 2022-08-08 | 2022-08-08 07:56:06
  | 132 | 10 | Roma, Roma Capitale, Lazio, Italia | IT | 41.937285393554 | 12.457783779498 | master | F | 2022-08-08 | 2022-08-08 | 2022-08-08 08:04:19
  | 133 | 10 | Roma, Roma Capitale, Lazio, Italia | IT | 41.937285393554 | 12.457783779498 | master | F | 2022-08-08 | 2022-08-08 | 2022-08-08 11:01:53
  | 134

## Steps to Reproduce
<!--- reproduce this issue; include code to reproduce, if relevant -->
1.
2.
3.
4.

## Context
<!--- What were you trying to do? -->

## Debug logs
<!-- include iOS / Android logs
- ios XCode logs,
- use #getLog #emailLog methods (@see docs)
- Android: $ adb logcat
-->
<details>
    <summary>Logs</summary>

```<!-- Syntax highlighting:  DO NOT REMOVE -->
PASTE_YOUR_LOGS_HERE

christocracy commented 1 year ago

What are you hoping to do with a distanceFilter of 20km?

It’s not going to save battery. The plugin will consume just as much energy with distanceFilter of 20000 vs 0.

If you want only periodic location updates, see Config.useSignificantChangesOnly.

marcob77 commented 1 year ago

What are you hoping to do with a distanceFilter of 20km?

It’s not going to save battery. The plugin will consume just as much energy with distanceFilter of 20000 vs 0.

If you want only periodic location updates, see Config.useSignificantChangesOnly.

Hi, thanks for answer. My need are to check if user change City,Country and send data to a server: so i dont need high precision about changing position (so i fixed distance filter 20km), but i need app to work in background as yours. Config.useSignificantChangesOnly works fine, but take position about every 1km (maybe i could have problem with privacy rules)so i dont know if its possible to change this behavior. Last but not the least, i need to use config usable also for android phone, because i will need also android version of my solution.

christocracy commented 1 year ago

Config.useSignificantChangesOnly is far more privacy friendly and doesn’t keep the location radios ON all the time as you’re currently doing, needlessly draining the user’s battery just as much as if following a driving route on a native Map app (Eg Google maps).

config.useSignificantChangesOnly works for both iOS and Android, in spite of what the docs may say.

marcob77 commented 1 year ago

Config.useSignificantChangesOnly is far more privacy friendly and doesn’t keep the location radios ON all the time as you’re currently doing, needlessly draining the user’s battery just as much as if following a driving route on a native Map app (Eg Google maps).

config.useSignificantChangesOnly works for both iOS and Android, in spite of what the docs may say.

Ty again. I will use and test with config.useSignificantChangesOnly