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

Android location timeout error in background mode since last week previously it was working

Open smartlogixliftor-netizen opened this issue 5 months ago • 2 comments

In my app I have integrate live tracking functionality at every 5 seconds I am fetching user's current location in both foreground and background mode which is previously working but since last week it has stopped working even in foreground mode as well it's taking time to fetch location as compare to previous.

Here, is my code

const getLocationWithRetry = async (retries = 3) => { try { return await getLocation(); } catch (error) { if (retries > 0) { console.log(🔁 Retrying... Attempts left: ${retries}); return getLocationWithRetry(retries - 1); } else { throw new Error('Failed to get location after multiple attempts'); } } };

const getLocation = async () => { return new Promise((resolve, reject) => { Geolocation.getCurrentPosition( position => resolve(position.coords), error => { console.error('Error getting location: ', error); if (error.code === 3) { console.log('Location request timed out. Retrying...'); resolve(getLocation()); } else { reject(error); }}, { enableHighAccuracy: true, // timeout: 20000, maximumAge: 10000, }, ); }); };

export const startBackgroundTask = async dispatch => { console.log('🚀 Starting background service...'); await BackgroundService.start(() => processTasks(dispatch), options); };

const processTasks = async dispatch => { while (BackgroundService.isRunning()) { try { const location = await getLocationWithRetry(); if (location) { const {accuracy, latitude, longitude} = location; console.log('location', location); if (accuracy > 50) { console.log('⚠️ Skipping inaccurate location:', accuracy); await sleep(5000); continue; } } } };

I have the same issue too

FurkanKayaDev avatar Sep 10 '25 10:09 FurkanKayaDev

There are some models with timeout for obtaining

zqf-00 avatar Sep 12 '25 09:09 zqf-00