react-native-background-geolocation
react-native-background-geolocation copied to clipboard
[Help Wanted]: Didn't get Enter/Exit event accurately in background mode in Real iOS device with real location testing in Debug ipa.
Required Reading
- [x] Confirmed
Plugin Version
4.18.6
Mobile operating-system(s)
- [x] iOS
- [ ] Android
Device Manufacturer(s) and Model(s)
iPhone
Device operating-systems(s)
16.7.11
React Native / Expo version
0.72.3
What do you require assistance about?
"BackgroundGeolocation.onGeofence()" only called first time when listener registered. But when I Re enter and Exit in the location again then the notifications from library triggered but this "BackgroundGeolocation.onGeofence()" not.
I have also used "BackgroundGeolocation.onLocation", it works every time with wired Debugging but when i test with Debug ipa with real Location moving in Real iOS device it does not triggered Event accurately.
[Optional] Plugin Code and/or Config
useEffect(() => {
if (!isClockedIn) return;
const polygonVertices = geoFancingData[0]?.fencingBound?.map((item: any) => [
parseFloat(item.lat),
parseFloat(item.lng),
]) || [];
if (
polygonVertices.length &&
(polygonVertices[0][0] !== polygonVertices[polygonVertices.length - 1][0] ||
polygonVertices[0][1] !== polygonVertices[polygonVertices.length - 1][1])
) {
polygonVertices.push(polygonVertices[0]);
}
let wasInside = false;
const locationHandler = (location) => {
const lat = location?.coords?.latitude;
const lng = location?.coords?.longitude;
const inside = isPointInPolygon([lat, lng], polygonVertices);
if (inside && !wasInside) {
displayNotification('geofence', 'ENTER (manual)');
console.log('ENTER (manual)');
Alert.alert('ENTER (manual)');
wasInside = true;
} else if (!inside && wasInside) {
displayNotification('geofence', 'EXIT (manual)');
console.log('EXIT (manual)');
Alert.alert('EXIT (manual)');
wasInside = false;
}
};
BackgroundGeolocation.ready({
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 10,
stopOnTerminate: false,
startOnBoot: true,
locationAuthorizationRequest: 'Always',
geofenceProximityRadius: 1000,
enableHeadless: true,
debug: true,
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
}, async (state) => {
if (!state.enabled) {
await BackgroundGeolocation.startGeofences();
}
BackgroundGeolocation.getState().then(state => {
console.log('[Geolocation State]', state);
});
await BackgroundGeolocation.addGeofence({
identifier: 'Home',
vertices: polygonVertices,
notifyOnEntry: true,
notifyOnExit: true,
notifyOnDwell: false,
loiteringDelay: 30000,
}).then(() => {
console.log('[addGeofence] success');
}).catch((error) => {
console.warn('[addGeofence] FAILURE:', error);
});
BackgroundGeolocation.changePace(true);
});
BackgroundGeolocation.onLocation(locationHandler);
return () => {
BackgroundGeolocation.removeListener('location', locationHandler);
};
}, [
isClockedIn,
JSON.stringify(geoFancingData[0]?.fencingBound) // Ensure clean re-execution only if bounds actually change
]);
[Optional] Relevant log output
See api docs .emailLog. Upload the log file here.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.