Skip to content

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

@smartlogixliftor-netizen

Description

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;
} } }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions