Location.startLocationUpdatesAsync seems to be running a few times a second

Hi, I’m playing around with Location.startLocationUpdatesAsync in dev (using expo app). I’m testing on my iphone X that is laying on my desk, and the function is being called multiple times a second even though none of the coordinate values have changed.

Is this expected behavior? In the docs, it says there is a timeinterval option, but it’s android only.

timeInterval ( number ) – Minimum time to wait between each update in milliseconds. Default value depends on accuracy option. ( Android only )

As per the advice of Scott P in the expo slack, I plugged in timeInterval and distanceInterval, which slowed down how often the function was called.

Relevant code:

export const BACKGROUND_LOCATION_UPDATES_TASK = 'background-location-updates'

TaskManager.defineTask(BACKGROUND_LOCATION_UPDATES_TASK, handleLocationUpdate)

export async function handleLocationUpdate({ data, error }) {
    if (error) {
		return
	}
	if (data) {
        try {
            const { locations } = data
            console.log('locations',locations)
        } catch (error) {
            console.log('the error',error)
        }
    }
}

export async function initializeBackgroundLocation(){
    let isRegistered = await TaskManager.isTaskRegisteredAsync(BACKGROUND_LOCATION_UPDATES_TASK)
    if (!isRegistered) await Location.startLocationUpdatesAsync(BACKGROUND_LOCATION_UPDATES_TASK, {
        accuracy: Location.Accuracy.High,
        /* after edit */
        timeInterval: 2500,
        distanceInterval: 5,
    })
}

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