HaylLtd / cordova-background-geolocation-plugin

Background and foreground geolocation plugin for Cordova.
Apache License 2.0
57 stars 66 forks source link

Locations are reported infrequently #167

Open jwasnoggin opened 1 year ago

jwasnoggin commented 1 year ago

Describe the bug Using this plugin in my app, locations are being recorded much less frequently than I expect. I have interval set to 60000 (1 minute), and stationaryRadius and distanceFilter set to 10. I would expect an update close to every minute, but instead it was only happening every 3-10 minutes typically. Sometimes if I opened Google Maps it would then send a location (I guess because the GPS was activated), but not always.

Is there any way I can set an expected frequency and have the app honour that?

My full config:

{
    locationProvider: BackgroundGeolocation.DISTANCE_FILTER_PROVIDER,
    desiredAccuracy: BackgroundGeolocation.MEDIUM_ACCURACY,
    stationaryRadius: 10,
    distanceFilter: 10,
    stopOnTerminate: false,
    notificationTitle: 'Background tracking',
    notificationText: 'enabled',
    debug: false,
    interval: frequencySeconds * 1000,
    startForeground: true,
    pauseLocationUpdates: false,
    saveBatteryOnBackground: false,
    maxLocations: 1000,
    url,
    syncUrl,
    httpHeaders,
    postTemplate
}

Expected behavior The app should report a location every minute (as long as the speed is less than 60 m/s).

Smartphone:

HarelM commented 1 year ago

I would consult the plugin's logs to see what might have caused this, also I would recommend trying all kind of configurations. If nothing helps feel free to add prints in the code. The plugin mainly send back what the OS sends it...

jwasnoggin commented 1 year ago

I had a look at the logs, doesn't seem to be any errors. There are a few gaps where nothing happens for several minutes, for example here between 17:36 and 17:45. The tracking was supposedly running the whole time.

[2023/10/27 17:45:03] com.marianhello.bgloc.PostLocationTask:Posting json to url: <REDACTED>
[2023/10/27 17:45:03] com.marianhello.bgloc.BackgroundGeolocationFacade:Received MSG_ON_LOCATION
[2023/10/27 17:45:03] com.marianhello.bgloc.PostLocationTask:Executing PostLocationTask#postLocation
[2023/10/27 17:45:03] com.marianhello.bgloc.service.LocationServiceImpl:New location BGLocation[gps <REDACTED>,<REDACTED> id=null acc=128 t=1698389101912 et=+24d23h42m30s40ms alt=49.660953606481414 vel=25.021564 bear=0.0 {Bundle[mParcelledData.dataSize=132]} locprov=0]
[2023/10/27 17:45:03] com.marianhello.bgloc.provider.DistanceFilterLocationProvider:Requesting location updates from provider gps
[2023/10/27 17:45:03] com.marianhello.bgloc.provider.DistanceFilterLocationProvider:Setting pace: true
[2023/10/27 17:45:03] com.marianhello.bgloc.provider.DistanceFilterLocationProvider:Updating distanceFilter: new=635 old=235
[2023/10/27 17:45:03] com.marianhello.bgloc.provider.DistanceFilterLocationProvider:Location change: Location[gps <REDACTED>,<REDACTED> hAcc=128 et=+24d23h42m30s40ms alt=49.660953606481414 vel=25.021564 bear=0.0 vAcc=128 sAcc=0 bAcc=5 {Bundle[mParcelledData.dataSize=132]}] isMoving=true
[2023/10/27 17:38:34] com.marianhello.bgloc.service.LocationServiceImpl:Network condition changed has connectivity: true
[2023/10/27 17:38:12] com.marianhello.bgloc.service.LocationServiceImpl:Network condition changed has connectivity: false
[2023/10/27 17:36:14] com.marianhello.bgloc.PostLocationTask:Posting json to url: <REDACTED>
[2023/10/27 17:36:14] com.marianhello.bgloc.BackgroundGeolocationFacade:Received MSG_ON_LOCATION
[2023/10/27 17:36:14] com.marianhello.bgloc.PostLocationTask:Executing PostLocationTask#postLocation
[2023/10/27 17:36:14] com.marianhello.bgloc.service.LocationServiceImpl:New location BGLocation[gps <REDACTED>,<REDACTED> id=null acc=96 t=1698388572982 et=+24d23h33m41s137ms alt=82.85539544211348 vel=15.107342 bear=0.0 {Bundle[mParcelledData.dataSize=132]} locprov=0]
[2023/10/27 17:36:14] com.marianhello.bgloc.provider.DistanceFilterLocationProvider:Location change: Location[gps <REDACTED>,<REDACTED> hAcc=96 et=+24d23h33m41s137ms
HarelM commented 1 year ago

It might be related to distance? You also have medium accuracy which might be affecting somehow, IDK, it's complicated... Adding logs to the java code might help I guess...