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

[Help Wanted]: App not sending locations to server

Open jayesh-vyas opened this issue 6 months ago • 6 comments

Required Reading

  • [x] Confirmed

Plugin Version

4.18.6

Mobile operating-system(s)

  • [ ] iOS
  • [x] Android

Device Manufacturer(s) and Model(s)

Pixel emulator

Device operating-systems(s)

Android 14

React Native / Expo version

No response

What do you require assistance about?

The app only sends location logs data to the server only if debug:true otherwise it doesnt sends the data to the server

[Optional] Plugin Code and/or Config

useEffect(() => {
    const initTracking = async () => {
      const token = await getToken();

      BackgroundGeolocation.ready(
        {
          desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
          distanceFilter: 20,
          stopOnTerminate: false,
          startOnBoot: true,
          debug: true,
          isMoving: true,
          logLevel: BackgroundGeolocation.LOG_LEVEL_OFF,
          autoSync: true,
          batchSync: true,
          maxRecordsToPersist: 1000,
          url: 'http://192.168.1.35:3000/api/live/log-location',
          headers: {
            Authorization: `Bearer ${token}`,
          },
          params: {
            user_id: userId,
            orgid: orgId,
          },
          httpRootProperty: '.',
          locationTemplate:
            '{"latitude":<%= latitude %>,"longitude":<%= longitude %>,"timestamp":"<%= timestamp %>"}',
        },
        async state => {
          setIsTracking(state.enabled);
          loadLocationData();
        },
      );

      BackgroundGeolocation.onLocation(location => {
        console.log('[onLocation]', location);
        setCurrentLocation(
          `${location.coords.latitude.toFixed(
            5,
          )}, ${location.coords.longitude.toFixed(5)}`,
        );
      });

      
      BackgroundGeolocation.onLocationError(error => {
        console.error('[Location Error]', error);
      });

      return () => {
        BackgroundGeolocation.removeAllListeners();
      };
    };

    initTracking();
  }, []);

[Optional] Relevant log output


jayesh-vyas avatar Jun 04 '25 13:06 jayesh-vyas

debug: true has no effect on performance. It's as superstitious as believing black cats crossing your path cause bad luck.

The first thing to do when something unusual happens (before posting an issue) is analyze the plugin logs. See Wiki "Debugging".

christocracy avatar Jun 04 '25 14:06 christocracy

It's not affecting the performance, it's like it doesn't work when debug is false, and let me clear, I have non-licenced version, so it that a reason?

jayesh-vyas avatar Jun 05 '25 05:06 jayesh-vyas

The first thing to do when something unusual happens (before posting an issue) is analyze the plugin logs. See Wiki "Debugging"

See wiki “Debuggjng” and learn to provide logs here.

christocracy avatar Jun 05 '25 09:06 christocracy

Okay so it worked after doing some fixes but still i wanted to confirm one thing, is this isMoving:true required for emulator to work? chatGPT told that it does require on the emulator but wont require on real devices.

jayesh-vyas avatar Jun 05 '25 12:06 jayesh-vyas

Read the wiki “Philosophy of Operation”.

The plug-in triggers location-tracking when the device is detected to be moving (via motion api).

The motion api doesn’t work in the emulator. In the emulator, you have to manually tell the plug-in to enter the moving state and start listening to location changes.

It’s also mentioned in the wiki “Debugging” that I’ve pointed you at twice.

christocracy avatar Jun 05 '25 12:06 christocracy

My bad, btw thanks!

jayesh-vyas avatar Jun 05 '25 12:06 jayesh-vyas

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Jul 06 '25 02:07 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jul 20 '25 02:07 github-actions[bot]