react-native-background-geolocation
react-native-background-geolocation copied to clipboard
Background update not happening
Location update Foreground and Background
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
import React, { useEffect, useState } from 'react';
import Geolocation from 'react-native-geolocation-service';
import BackgroundGeolocation from 'react-native-background-geolocation';
const useLocation = () => {
const [location, setLocation] = useState(null);
useEffect(() => {
let isMounted = true;
// Request foreground location updates
Geolocation.getCurrentPosition(
position => {
if (isMounted) {
setLocation({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
});
}
},
error => {
console.log('Foreground location error: ', error);
},
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
);
// Configure background location updates
BackgroundGeolocation.configure({
desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
stationaryRadius: 50,
distanceFilter: 1,
notificationTitle: 'Background tracking',
notificationText: 'enabled',
debug: false,
startOnBoot: false,
stopOnTerminate: true,
locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,
interval: 10000,
fastestInterval: 5000,
activitiesInterval: 10000,
stopOnStillActivity: false,
});
// Register background location event handler
BackgroundGeolocation.on('location', location => {
if (isMounted) {
setLocation({
latitude: location.latitude,
longitude: location.longitude,
});
}
});
// Start background location tracking
BackgroundGeolocation.start();
return () => {
isMounted = false;
// Stop background location tracking when component unmounts
BackgroundGeolocation.stop();
BackgroundGeolocation.removeAllListeners();
};
}, []);
return location;
};
export default useLocation;
Expected Behavior
Actual Behavior
Steps to Reproduce
Context
I want to fetch location update in the foreground and background, I am using an above custom hook to get location, i don't know where went wrong, it's not working My requirement
- Continuous fetch location foreground and background
Debug logs
Logs
PASTE_YOUR_LOGS_HERE
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
- see wiki “Debugging”
- See wiki “Philosophy of Operation”
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.