Expo Location and Task Manager not working on Android

Please provide the following:

  1. SDK Version: 37
  2. Platforms(Android/iOS/web/all): all

Hi there!

I am a strange problem with the Location Api and Task Manager, while geofencing on Android.

The below code works perfectly on IOS standalone and when ran through EXPO but when I make a standalone android app nothing happens, the task manager is running and has correctly received the coordinates of the geofenced areas as I can see it logging in the console but it does not detect when I entered/left a geofenced area.

Is there an extra step you need to do in order for it to work on android? can anyone please help.

CODE BELOW

const LOCATION_API = ‘background-location-task’;

TaskManager.defineTask(LOCATION_API, ({ data: { eventType, region }, error }) => {
if (error) {
// check error.message for more details.
return;
}
if (eventType === Location.GeofencingEventType.Enter) {
const { identifier } = region
let identifierReturned = [
identifier
]
console.log(‘GeoLocation Detected you have entered site -’, identifierReturned)
store.dispatch(dispatchEnteredSite(identifierReturned));

} else if (eventType === Location.GeofencingEventType.Exit) {
    const { identifier } = region
    let identifierReturned = [
        identifier
    ]
    store.dispatch(dispatchLastSite(identifierReturned));
    console.log('Left Site Dispatched to Redux Store',identifierReturned)
}

});

startGeofencing = async () => {
Analytics.logEvent(‘Ran_Function’, { name: ‘startGeofencing’});
const { status } = await Location.requestPermissionsAsync();
if (status === ‘granted’) {
console.log(“Permissions granted, fetching current location”)
const loc = await Location.getCurrentPositionAsync();
console.log("Current Location: ", loc)
this.setState({
currentLocation: loc
})
if (!TaskManager.isTaskDefined(‘LOCATION_API’)) {
Location.startGeofencingAsync(LOCATION_API, this.props.coorinatesForApi), {
accuracy: Location.Accuracy.BestForNavigation,
};
}}
};

1 Like

Hey there!

As you can see here I am having somewhat the same issue. Have you tried running it on an AVD device? (Android simulator). For me, through the expo app, it works flawless every single time in AVD. On iOS physical device with expo custom, it works flawless. On iOS in production, flawless. Android device through expo 10% of the time. Android production 5% of the time.

What’s funny is - during the morning hours - on android through custom app it works 100% of the time. This morning during my testing it worked from 7AM CST-10:50AM CST. I wish I was making that up.

If I find a solution I will update my thread and this thread here.

Thanks for this coding related information…!!!

Can i see more from you on this topic..???

I got really good information from this content.thanks for sharing.

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