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

cannot read the property ready of null

Open Naveenkumar-1411 opened this issue 1 year ago • 10 comments

import React, { useState, useEffect } from 'react'; import { View, Button, Alert, StyleSheet } from 'react-native'; import BackgroundGeolocation from 'react-native-background-geolocation'; import Constants from 'expo-constants'; import * as Application from 'expo-application'; import axios from 'axios'; import BASE_URL from '../../../../utils/Api'; import { useDispatch, useSelector } from "react-redux"; const Homeview = () => { const [isTracking, setIsTracking] = useState(false); const [deviceUuid, setDeviceUuid] = useState('');

const loginUser = useSelector((state) => state.user.user); const employee_id = loginUser.profile.id;

useEffect(() => { // Get the device unique ID const fetchDeviceUuid = () => { const uuid = Constants.platform.android ? Application.getAndroidId() : Constants.installationId; setDeviceUuid(uuid); };

fetchDeviceUuid();

BackgroundGeolocation.onLocation(async (location) => {
  const locationData = {
    device_uuid: deviceUuid,
    employee_id,
    location: {
      coords: {
        latitude: location.coords.latitude,
        longitude: location.coords.longitude,
        altitude: location.coords.altitude,
        accuracy: location.coords.accuracy,
        speed: location.coords.speed,
      },
      is_moving: location.is_moving ? 1 : 0,
      provider: {
        network: location.provider.network || "",
        status: location.provider.status || "",
        gps: location.provider.gps || "",
        enabled: location.provider.enabled || "",
      },
      activity: {
        type: location.activity.type || "",
      },
      battery: {
        is_charging: location.battery.is_charging ? 1 : 0,
        level: location.battery.level,
      },
    },
  };

  try {
    await axios.post(`${BASE_URL}/location/track`, locationData, {
      headers: {
        Authorization: `Bearer ${loginUser.auth_key}`,
      },
    });
  } catch (error) {
    console.error("Error sending location data:", error);
  }
});

// Clean up
return () => {
  BackgroundGeolocation.removeListeners();
};

}, [deviceUuid]);

const startTracking = () => { BackgroundGeolocation.ready({ desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH, distanceFilter: 50, stopOnTerminate: false, startOnBoot: true, debug: false, logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE, }, (state) => { if (!state.enabled) { BackgroundGeolocation.start(); } });

setIsTracking(true);

};

const stopTracking = () => { BackgroundGeolocation.stop(); setIsTracking(false); };

return ( <View style={styles.container}> <Button title={isTracking ? "Stop Tracking" : "Start Tracking"} onPress={isTracking ? stopTracking : startTracking} /> </View> ); };

const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', }, });

export default Homeview; this is my code i getting the error that Backgroundgeolocation type error cannot read the ready the property ready of null start of the null stop of the null

Naveenkumar-1411 avatar Jul 17 '24 04:07 Naveenkumar-1411

WhatsApp Image 2024-07-17 at 3 39 00 PM (1) WhatsApp Image 2024-07-17 at 3 39 00 PM here is the image i have uploaded

Naveenkumar-1411 avatar Jul 17 '24 10:07 Naveenkumar-1411

please some do needfull

Naveenkumar-1411 avatar Jul 17 '24 10:07 Naveenkumar-1411

If the method doesn't exist, then your app things the plugin is not installed.

Also, you completely ignored the required issue template so I don't even know anything about your setup.

Your Environment

  • Plugin version:
  • Platform: iOS or Android
  • OS version:
  • Device manufacturer / model:
  • React Native version (react-native -v):
  • Plugin config
PASTE_YOUR_CODE_HERE

Expected Behavior

Actual Behavior

Steps to Reproduce

Context

Debug logs

Logs
PASTE_YOUR_LOGS_HERE

christocracy avatar Jul 17 '24 20:07 christocracy

"react-native": "0.74.1",
platform :Android,
os Version: Android13,14,
Device ,Vivo y021,iqoo Z7
plugin version:
expo-gradle-ext-vars": "^0.1.2",
    "react-native-background-fetch": "^4.2.5",
    "react-native-background-geolocation": "^4.16.5",
    plugin config:
       [
        "react-native-background-geolocation",
        {
          "license": "my license"
        }
      ],
      [
        "expo-gradle-ext-vars",
        {
          "googlePlayServicesLocationVersion": "21.1.0",
          "appCompatVersion": "1.4.2"
        }
      ],
      "react-native-background-fetch"
    ],

Naveenkumar-1411 avatar Jul 29 '24 07:07 Naveenkumar-1411

See the last section of Setup Instructions named "Re-build".

christocracy avatar Jul 29 '24 13:07 christocracy

whether i need to prebuild and then work on it

Naveenkumar-1411 avatar Jul 29 '24 16:07 Naveenkumar-1411

After adding the plug-in, you must “prebuild” or the plug-in doesn’t exist.

christocracy avatar Jul 29 '24 16:07 christocracy

Wheter i need to convert my Expo App into the native cli

Naveenkumar-1411 avatar Jul 30 '24 07:07 Naveenkumar-1411

or eas build

christocracy avatar Jul 30 '24 09:07 christocracy

if i make eas build how it work if i need to make both Apple and Andoid build it requires Apple id

Naveenkumar-1411 avatar Jul 31 '24 10:07 Naveenkumar-1411

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

github-actions[bot] avatar Sep 01 '24 02:09 github-actions[bot]

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

github-actions[bot] avatar Sep 16 '24 02:09 github-actions[bot]