Closed Nader-CS closed 2 weeks ago
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_MEDIUM, distanceFilter: 250, stopOnStationary: true, stopTimeout: 5, debug: __DEV__, logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE, stopOnTerminate: false, startOnBoot: true, batchSync: false, autoSync: true, foregroundService: true, enableHeadless: true, notification: notificationConfig, url: `${Config.API_URL}api/v1/driver_locations`, method: 'POST', headers: { Authorization: `Bearer ${access_token}`, }, params: {orderId: order?.id},
to get current user location
always give me timeout with error 408
* This hook will be used to access user location and send it to the server * features: * - get user location [done]. * - send user location to server [done]. */ import {useCallback, useEffect, useMemo} from 'react'; import BackgroundGeolocation from 'react-native-background-geolocation'; import {useState} from 'react'; import {useDispatch, useSelector} from 'react-redux'; import {getDriverLocation, getToken, getCurrentOrder} from '@selectors'; import Config from 'react-native-config'; import colors from '@common/colors'; import {t} from 'i18next'; import {setDriverLocation} from '@slices'; import {useGetUserQuery} from '@services/user'; import crashlytics from '@react-native-firebase/crashlytics'; const notificationConfig = { title: t('hive'), text: t('you_are_online'), color: colors.notification, largeIcon: 'drawable/hive_logo', smallIcon: 'drawable/hive_logo', sticky: true, }; const useTracking = () => { const dispatch = useDispatch(); const {data: driverData} = useGetUserQuery(); const {access_token} = useSelector(getToken) || {}; const [isReady, setIsReady] = useState(false); const location = useSelector(getDriverLocation); const order = useSelector(getCurrentOrder); const configuration = useMemo(() => { return { desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_MEDIUM, distanceFilter: 250, stopOnStationary: true, stopTimeout: 5, debug: __DEV__, logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE, stopOnTerminate: false, startOnBoot: true, batchSync: false, autoSync: true, foregroundService: true, enableHeadless: true, notification: notificationConfig, url: `${Config.API_URL}api/v1/driver_locations`, method: 'POST', headers: { Authorization: `Bearer ${access_token}`, }, params: {orderId: order?.id}, }; }, [order?.id, access_token]); useEffect(() => { let locationSubscription; BackgroundGeolocation.ready({ ...configuration, }) .then(() => { locationSubscription = BackgroundGeolocation.onLocation( location => dispatch(setDriverLocation(location.coords)), error => { crashlytics().recordError(error); }, ); }) .catch(error => { crashlytics().recordError(error); }) .finally(() => { getLocation(); }); return () => { locationSubscription.remove(); }; }, []); const getLocation = async () => { const location = await BackgroundGeolocation.getCurrentPosition({ samples: 1, persist: false, }); dispatch(setDriverLocation(location.coords)); return location; }; const startTracking = () => { BackgroundGeolocation.start(); }; const stopTracking = () => { BackgroundGeolocation.stop(); }; const restartGeolocationService = useCallback(() => { BackgroundGeolocation.stop().then(() => { BackgroundGeolocation.setConfig({...configuration}).then(() => { BackgroundGeolocation.start(); }); }); }, [configuration]); return { isReady, getLocation, startTracking, stopTracking, location, restartGeolocationService, }; }; export default useTracking;
when i restart the phone , it working!
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.
Your Environment
Expected Behavior
to get current user location
Actual Behavior
always give me timeout with error 408
Steps to Reproduce
Context
Debug logs
Logs
``` PASTE_YOUR_LOGS_HERE ```