react-native-background-geolocation: We can't insert any coordinates in the server when the app is terminated (ANDROID)
Your Environment
- Plugin version: ^4.12.1
- Platform: Android
- OS version:
- Device manufacturer / model: SAMSUNG
- React Native version (
react-native -v): 0.64.0 - Plugin config
getBackgroundLocation = () => {
if (!this.bglocationSub.length) {
BackgroundGeolocation.start()
console.log('start getBackgroundLocation')
const backgroundGeolocation = BackgroundGeolocation.onLocation(
(location) => {
const { latitude, longitude } = location?.coords
if (this.state.coordinates?.latitude !== latitude || this.state.coordinates?.longitude !== longitude) {
console.log('on-going getBackgroundLocation')
const coordinates = {
latitude: Number(latitude),
longitude: Number(longitude),
timestamp: location.timestamp
}
console.log(coordinates)
// update local state
this.setState({
latitude: Number(latitude),
longitude: Number(longitude),
timestamp: location.timestamp,
coordinates,
error: null,
});
// update store
this.props.setJobCurrentLocation({
latitude: Number(latitude),
longitude: Number(longitude),
timestamp: location.timestamp,
coordinates,
});
this.updateRoutes(coordinates)
this.updateTruckLocation(coordinates)
this.sendNotifications(coordinates)
}
},
(error) => {
this.setState({ error: error.message });
}
)
BackgroundGeolocation.ready({
// Geolocation Config
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 10,
// Activity Recognition
stopTimeout: 5,
// Application config
debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
stopOnTerminate: false, // <-- Allow the background-service to continue tracking when user closes the app.
startOnBoot: true, // <-- Auto start tracking when device is powered-up.
batchSync: false, // <-- [Default: false] Set true to sync locations to server in a single HTTP request.
autoSync: true, // <-- [Default: true] Set true to sync each location to server as it arrives.
})
this.bglocationSub.push(backgroundGeolocation)
}
}
Expected Behavior
When the app is in the background it is not working, the location is stuck up and the coordinates are not saving in the server. Only the IOS platform is working while the ANDROID platform is not working fine.
The goal is for any platform the coordinates must be saved in the server.
Actual Behavior
When the app is in the background it is not working, the location is stuck up and the coordinates are not saving in the server.
Steps to Reproduce
- debug:true
Context
Debug logs
Logs
[{"lat": 14.7160773, "lng": 121.1318833, "timestamp": "2024-08-20T16:01:18.527Z"}] list of routes
LOG App has gone to the background!
LOG [{"context": undefined, "emitter": {"_disableCallsIntoModule": false, "_subscriber": [EventSubscriptionVendor]}, "eventType": "location", "key": 2, "listener": [Function handler], "remove": [Function anonymous], "subscriber": {"_currentSubscription": null, "_subscriptionsForType": [Object]}}]
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 28 (17 by maintainers)
Go do as I said.