Expo Location background task

SDK Version: 41.0.1
Platforms: Android + iOS

Hi,

I want to create an app similar to Traccar Client, that is a GPS tracker the user enable to emit each second his device position to a server (with POST requests).

To achieve this goal, I’m using the Expo Location lib with background task, that is working well if I’m moving. Unfortunately, if the device is not moving (so the location is the same), the new location callback is not triggered until next significant location delta (below the code I’m using).

Do you have any clue about how to trigger this location callback every second, even if the location is the same one?

Thank you in advance,
Regards

import * as Location from 'expo-location';
import * as TaskManager from 'expo-task-manager';

const TASK_FETCH_LOCATION = 'TASK_FETCH_LOCATION';

export class TrackingService {
    static start = () => {
        TaskManager.defineTask(TASK_FETCH_LOCATION, TrackingService.onLocation);
        Location.startLocationUpdatesAsync(TASK_FETCH_LOCATION, {
            accuracy: Location.Accuracy.Highest,
            timeInterval: 1000,
            deferredUpdatesInterval: 1000,
            activityType: Location.ActivityType.OtherNavigation,
            foregroundService: {
                notificationTitle: 'Using your location',
                notificationBody: 'To turn off, go back to the app and switch something off.',
            },
        });
    }

    // <------- This method is triggered only if there is a significant location change
    //  I want to trigger it every second, even if location is the same than previous one
    static onLocation = ({data, error}) => {
        console.log('New position:', data, error);
    }

    static stop = () => {
        Location.stopLocationUpdatesAsync(TASK_FETCH_LOCATION);
    }
}

Hey @pavinain, are you saying that the callback is not being triggered for both iOS and Android? Can you try setting your distanceInterval to 0,

Cheers,
Adam

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.