Please provide the following:
- SDK Version: 37
- 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,
};
}}
};