react-native-background-geolocation
react-native-background-geolocation copied to clipboard
Location not sent to server when app running in physical device but it is working when app running using emulator
Your Environment
- Plugin version:4.8.2
- Platform: Android
- OS version:11
- Device manufacturer / model:all device
- React Native version (
react-native -v):0.69.1 - Plugin config
const DriverDutyOnSatus = () => {
const [enabled, setEnabled] = React.useState(false);
const [location, setLocation] = React.useState('');
React.useEffect(() => {
/// 1. Subscribe to events.
const onLocation:Subscription = BackgroundGeolocation.onLocation((location) => {
console.log('[onLocation]', location);
setLocation(JSON.stringify(location, null, 2));
})
const onMotionChange:Subscription = BackgroundGeolocation.onMotionChange((event) => {
if (event.isMoving) {
console.log("[onMotionChange] Device has just started MOVING ", event.location);
} else {
console.log("[onMotionChange] Device has just STOPPED: ", event.location);
}
});
const onActivityChange:Subscription = BackgroundGeolocation.onActivityChange((event) => {
console.log('[onActivityChange]', event);
})
const onProviderChange:Subscription = BackgroundGeolocation.onProviderChange((event) => {
console.log('[onProviderChange]', event);
})
/// 2. ready the plugin.
BackgroundGeolocation.ready({
// Geolocation Config
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 1,
// 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.
// HTTP / SQLite config
url: 'https://ourtestserver.com/locations',
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.
headers: { // <-- Optional HTTP headers
"X-FOO": "bar"
},
arams: { // <-- Optional HTTP params
"user_id": 25,
"device_id": "abc123"
}
}).then((state) => {
setEnabled(state.enabled)
console.log("- BackgroundGeolocation is configured and ready: ", state.enabled);
BackgroundGeolocation.start();
});
return () => {
// Remove BackgroundGeolocation event-subscribers when the View is removed or refreshed
// during development live-reload. Without this, event-listeners will accumulate with
// each refresh during live-reload.
onLocation.remove();
onMotionChange.remove();
onActivityChange.remove();
onProviderChange.remove();
}
}, []);
/// 3. start / stop BackgroundGeolocation
React.useEffect(() => {
if (enabled) {
BackgroundGeolocation.start();
} else {
BackgroundGeolocation.stop();
setLocation('');
}
}, [enabled]);
return (
<View style={{alignItems:'center'}}>
<Text>Click to enable BackgroundGeolocation</Text>
<Switch value={enabled} onValueChange={setEnabled} />
<Text style={{fontFamily:'monospace', fontSize:12}}>{location}</Text>
</View>
)
}
export default DriverDutyOnSatus;
## Expected Behavior
send updated location to our test server using url configuration when app running in physical device(debug .apk)
## Actual Behavior
updated location send to our test server when app running using emulator.
Device manufacturer / model:all device
All devices in the world? Surely you can mention a specific device / devices.
see https://dontkillmyapp.com
It works on the devices I test on:
- Nexus 4 @ 4.4.4
- Nexus 5 @ 6.0.1
- Motorola Moto G @ 6.0.0
- Google Pixel @ 10
- Google Pixel 3a @ 12
- Google Pixel 6 @ 13
- Samsung Galaxy S20 FE @ 12.0.0
- Samsung J @ 6.0.1
- Samsung A510 @ 8.0.0
- Huawei P20 Lite (ANE-LX3) @ 8.0.0
- XIAOMI MI A2 Lite @ 10.0.0
- Nokia TA-1027 @ 8.0.0
- OnePlus A5010 @ 9.0.0
Are you going outside moving for at least 1000 meters?
Are you going outside moving for at least 1000 meters?
Hi christocracy Thanks for your response. Actually I am able to seen the updated location on device on view when I am moving , but that updated location not sent to our server. I configure my server url inside BackgroundGeolocation.ready like url: 'https://ourtestserver.com/locations', but when I am running app inside emulator I am able to see the updated location on view as well as app able to send updated location to server also.
but that updated location not sent to our server.
And what do the plug-in’s logs say? See wiki Debugging
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.