react-native-background-geolocation icon indicating copy to clipboard operation
react-native-background-geolocation copied to clipboard

Getting issue in setting the interval for location update in database

Open GurjeetLamba opened this issue 2 years ago • 31 comments

Your Environment

"react-native-background-fetch": "^4.1.10", "react-native-background-geolocation": "^4.12.1",

  • Platform: Android
  • OS version: 12
  • Device manufacturer and model: OPPO CPH2095
  • React Native version: 0.64
  • Plugin config
  const state:State = await BackgroundGeolocation.ready({
      url:"https://hkdk.events/9JXddKxb5fnn",
     reset: false,
     debug: true,
      locationTemplate: '{"Latitude":<%= latitude %>,"Longitude":<%= longitude %>,"TimeStamp": "<%= timestamp %>"}',
      autoSync:true,
      deferTime:180000,
   
      params: {
      ClientId:respo_storage.data.ClientId,
     
      },
      headers: { 
     authorization: "Bearer "+getToken.data.Token, 
      source:source
      },
      logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
      desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
      distanceFilter: 0,
      locationUpdateInterval:180000,
      allowIdenticalLocations:false,
      stopTimeout: 5,
      fastestLocationUpdateInterval:180000,
   
      locationAuthorizationRequest: 'Always',
      backgroundPermissionRationale: {
        title: "Allow {applicationName} to access this device's location even when closed or not in use.",
        message: "This app collects location data to enable recording your trips to work and calculate distance-travelled.",
        positiveAction: 'Change to "{backgroundPermissionOptionLabel}"',
        negativeAction: 'Cancel'
      },
      maxDaysToPersist: 14,
     
      stopOnTerminate: false,
      startOnBoot: true,
      enableHeadless: true,
    
    });

## Expected Behavior
Location must be updated in db exactly after 3 min even in still mode or moving ## Actual Behavior

Actual Behaviour
Location is updating most after 3 min but in rare cases it updates after 2 min , and multiple locations at same time## Steps to 

GurjeetLamba avatar Jul 04 '23 10:07 GurjeetLamba

This issue is not resolved yet

GurjeetLamba avatar Jul 04 '23 11:07 GurjeetLamba

reset: false,

Do you know what this does? Why do you set it to false?

christocracy avatar Jul 04 '23 11:07 christocracy

This was set to false in Demo Application provided in the library , I didn't get the meaning of it What exactly it is doing

GurjeetLamba avatar Jul 04 '23 11:07 GurjeetLamba

Delete that whole line from your Config reset: false.

christocracy avatar Jul 04 '23 12:07 christocracy

ok

GurjeetLamba avatar Jul 04 '23 13:07 GurjeetLamba

Tried deleting this but Still getting issue with the Accuracy If I use locationUpdateInterval instead of distance filter , Its our requirement that we need to update location after specific interval also getting issue with still mode , latitude and longitude are not accurate in still mode const state: State = await BackgroundGeolocation.ready({

  url: "http://92.204.135.120:8099/TomAPI/SaveLocationInformation",
  debug: true,
  logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
  desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_NAVIGATION,
  distanceFilter: 0,
  locationUpdateInterval: interval,
  stopTimeout: 5,
  locationTemplate: '{"Latitude":<%= latitude %>,"Longitude":<%= longitude %>,"TimeStamp": "<%= timestamp %>"}',
  locationAuthorizationRequest: 'Always',
  backgroundPermissionRationale: {
    title: "Allow {applicationName} to access this device's location even when closed or not in use.",
    message: "This app collects location data to enable recording your trips to work and calculate distance-travelled.",
    positiveAction: 'Change to "{backgroundPermissionOptionLabel}"',
    negativeAction: 'Cancel'
  },
  headers: {
    authorization: "Bearer " + getToken.data.Token,
    source: source
  },
  params: {
    ClientId: respo_storage.data.ClientId,
  },
  batchSync: true,
  autoSync: true,
  maxDaysToPersist: 14,
  stopOnTerminate: false,
  startOnBoot: true,
  enableHeadless: true
});

GurjeetLamba avatar Jul 05 '23 16:07 GurjeetLamba

latitude and longitude are not accurate in still mode

What makes you suspect that they’re “not accurate”?

christocracy avatar Jul 05 '23 16:07 christocracy

I am showing the lat long on map and it is showing in slightly different position from where I was actually situated

GurjeetLamba avatar Jul 05 '23 17:07 GurjeetLamba

And why are you not showing me this map?

christocracy avatar Jul 05 '23 17:07 christocracy

ok I will share the map screenshot also

GurjeetLamba avatar Jul 05 '23 17:07 GurjeetLamba

Screenshot 2023-07-05 at 11 47 29 PM As shown in the image the marker showing away (at 9.13) is at the time when I was at my home where a group of markers are shown

GurjeetLamba avatar Jul 05 '23 18:07 GurjeetLamba

Do you know that the geolocation accuracy while indoors is 40-60 meters? GPS only works outdoors (accuracy ~5 meters).

Do you know that a geolocation is not a simple point in space? It’s a circle of probability with radius location.coords.accuracy meters. The real location of the device is somewhere in that circle.

christocracy avatar Jul 05 '23 18:07 christocracy

I suggest you go outside for a nice long test of >1km.

christocracy avatar Jul 05 '23 18:07 christocracy

@christocracy We are facing this issue sometimes during walk also, If I use distance filter accuracy is better, But we need to update location after a time interval in minutes(3 min. or 5 min) thats why I am using locationUpdateInterval , but getting issue in accuracy with it and while in still mode interval also get disturbs location update after random intervals

GurjeetLamba avatar Jul 10 '23 05:07 GurjeetLamba

Plugin version:0.6.3

There is no such thing as 0.6.3. Where do you get this version number from?

christocracy avatar Jul 10 '23 13:07 christocracy

sorry I have updated the version number , I am using the latest version for both the libraries , Please suggest something for location update interval issue

GurjeetLamba avatar Jul 11 '23 05:07 GurjeetLamba

I have no suggestion for your problem.

it’s recommended to use distanceFilter, it saves energy. Do you know that iOS doesn’t even allow time based location updates?

christocracy avatar Jul 11 '23 12:07 christocracy

yes , but Is there any other way that I could know for how long the device is in still mode , so that I can send this to API that device is not moving in this time , then I can use distance Filter also which is giving better accuracy ,As I tested today

GurjeetLamba avatar Jul 11 '23 12:07 GurjeetLamba

but Is there any other way that I could know for how long the device is in still mode

That would be the time-difference between onMotionChange events.

christocracy avatar Jul 11 '23 12:07 christocracy

if device is in still mode for 15 minutes then onMotionChange event will occur if device moves after 15 minutes ?

GurjeetLamba avatar Jul 11 '23 12:07 GurjeetLamba

Have you read the wiki “Philosophy of Operation”?

do you understand what Config.stopTimeout is?

do you understand when onMotionChange fires?

christocracy avatar Jul 11 '23 12:07 christocracy

yes , but I was just confirming

GurjeetLamba avatar Jul 11 '23 12:07 GurjeetLamba

Screenshot 2023-07-11 at 11 02 14 PM Screenshot 2023-07-11 at 11 14 09 PM

In the First Image , It is the location when I left from my home on vehicle (at 8:15) and In second screenshot it is the location where I stopped , In between that I didn't got any location , But when I was coming back to home all the locations are uploaded

GurjeetLamba avatar Jul 11 '23 17:07 GurjeetLamba

Looks good to me.

christocracy avatar Jul 11 '23 17:07 christocracy

But after 8:15 I got only one location at 8:23 , What could be the reason of that gap ? Now I am using distance filter

GurjeetLamba avatar Jul 11 '23 17:07 GurjeetLamba

I have no idea. Why don’t you fetch the logs from the plug-in with .emailLog method and see what the plug-in was saying in its logs?

christocracy avatar Jul 11 '23 17:07 christocracy

See wiki Debugging

christocracy avatar Jul 11 '23 17:07 christocracy

I have no idea. Why don’t you fetch the logs from the plug-in with .emailLog method and see what the plug-in was saying in its logs?

ok

GurjeetLamba avatar Jul 11 '23 17:07 GurjeetLamba

69ce9530-d4e6-41f2-8035-3b90d5653bcf.gz

I am not able to read the error from logs , please help me here

GurjeetLamba avatar Jul 24 '23 11:07 GurjeetLamba

The file is gzipped. You need to unzip it.

christocracy avatar Jul 25 '23 01:07 christocracy