react-native-background-geolocation
react-native-background-geolocation copied to clipboard
cannot read the property ready of null
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
here is the image i have uploaded
please some do needfull
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
"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"
],
See the last section of Setup Instructions named "Re-build".
whether i need to prebuild and then work on it
After adding the plug-in, you must “prebuild” or the plug-in doesn’t exist.
Wheter i need to convert my Expo App into the native cli
or eas build
if i make eas build how it work if i need to make both Apple and Andoid build it requires Apple id
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.