Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I start background geolocation tracking, the initial state is is_moving = false. When my device starts moving, it takes some time to activate background geolocation tracking, and when I stop moving, it takes too much time to change is_moving = false. What should I do? #2228

Open
Dhamu143 opened this issue Dec 14, 2024 · 9 comments

Comments

@Dhamu143
Copy link

Dhamu143 commented Dec 14, 2024

const setTracking = async () => {
await BackgroundGeolocation.ready({
reset: true,
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
distanceFilter: 0,
stopOnTerminate: false,
startOnBoot: true,
debug: false,
locationUpdateInterval: 1000,
fastestLocationUpdateInterval: 1000,
notificationsEnabled: true, // Show a notification while tracking in the background
notificationTitle: 'Tracking Location', // Title of the notification
notificationText: 'Your location is being tracked for safety',
notificationIconColor: '#000000',
geofenceProximityRadius: 5000,
geofenceInitialTriggerEntry: true,
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
locationAuthorizationRequest: 'Always',
backgroundPermissionRationale: {
title: 'Allow App to access your location in the background?',
message:
'test',
positiveAction: 'Change to {backgroundPermissionOptionLabel}',
negativeAction: 'Cancel',
},
autoSync: true,
})
.then(state => {
console.log('[BackgroundGeolocation ready]', state);

  if (!state.enabled) {
    BackgroundGeolocation.start(() => {
      console.log('- BackgroundGeolocation started');
    });
  }
})
.catch(error => {
  console.error('[BackgroundGeolocation ready failed]', error);
});

BackgroundGeolocation.onLocation(
location => {
console.warn('[Location Update]', location);

  UpdateToFirebaseDB({
    currentLat: location.coords.latitude,
    currentLong: location.coords.longitude,
    BatteryIndicator: location.battery.level,
    is_moving: location.is_moving,
    tracking: true,
  });

  if (location.is_moving) {
    isMoving = true;
  } else {
    if (isMoving) {
      //At this time show arrival pop_up
      socket.emit('emitarrivalpopup', {socketId: socket.id});
      isMoving = false;
    }
  }
  locationData = location;
},
error => {
  console.log('[location] ERROR: ', error);
},

);

const onMotionChange = location => {
console.log('[motionchange]', location);

const message = location.isMoving
  ? 'Device is moving. Current location: ' +
    JSON.stringify(location, null, 2)
  : 'Device is stationary. Current location: ' +
    JSON.stringify(location, null, 2);

if (location.isMoving) {
  console.log('Device is moving');
} else {
  console.log('Devise is Stationary');
}

};

const onActivityChange = activityEvent => {
console.log('[activitychange]', activityEvent);
};
const onProviderChange = providerEvent => {
console.log('[providerchange]', providerEvent);
};

BackgroundGeolocation.onMotionChange(onMotionChange);
BackgroundGeolocation.onActivityChange(onActivityChange);
BackgroundGeolocation.onProviderChange(onProviderChange);
};

When I start background geolocation tracking, the initial state is is_moving = false. When my device starts moving, it takes some time to activate background geolocation tracking, and when I stop moving, it takes too much time to change is_moving = false. What should I do?

@christocracy
Copy link
Member

See wiki “Philosophy of Operation”.
see API docs Config.stopTimeout

@christocracy
Copy link
Member

Also, the issue template asked for a lot of information that you ignored,

  • plug-in version
  • Device model / manufacturer
  • iOS or Android

@Dhamu143
Copy link
Author

Dhamu143 commented Dec 17, 2024

When my device in background the Geolocation background Tracking not working so What should I do?

plug-in version :-4.17.5
Device Name:-Redmi Note 8
Device Model:-M1908C3JI
Android

@christocracy
Copy link
Member

See wiki “Debugging”.

Learn to listen to the plug-in debug soundFX (see api docs Config.debug).

learn to observe the plug-in’s incredibly verbose logs. See api docs “.emailLog”.

@Dhamu143
Copy link
Author

When I start background geolocation, the Tracking Location takes too much time to activate, and sometimes it does not activate at all. What should I do?
Can you please explain in detail.

@christocracy
Copy link
Member

takes too much time to activate

How long is too long? The plug-in typically requires movement of at least 200 meters before tracking automatically engages.

for device-specific issues, see https://dontkillmyapp.com

@Dhamu143
Copy link
Author

My question is, when my app starts, the UI works perfectly, but when the Background Geolocation is triggered, the UI freezes. What is the solution to prevent my UI from freezing?

@christocracy
Copy link
Member

Show me plug-in logs from $ adb logcat *:S TSLocationManager:V when this phenomenon occurs.

@Dhamu143
Copy link
Author

When I start background geolocation tracking and then terminate my app, the background geolocation tracking plugin stops working, and I can no longer get the latitude and longitude. What should I do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants