Skip to content

[Help Wanted]: I'm testing this package in my flutter app to use geofencing with optimal battery usages .My main goal is to achieve the best battery optimization without compromising on accuracy #1484

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

Open
2 of 3 tasks
NishantTpm opened this issue May 12, 2025 · 12 comments

Comments

@NishantTpm
Copy link

Required Reading

  • Confirmed

Plugin Version

flutter_background_geolocation: ^4.16.9

Mobile operating-system(s)

  • iOS
  • Android

Device Manufacturer(s) and Model(s)

Google pixel 9 pro

Device operating-systems(s)

Android 13

What do you require assistance about?

I'm testing this package in my flutter app to use geofencing with optimal battery usages , Geofencing works well but, it significantly drains battery too much. My main goal is to achieve the best battery optimization without compromising on accuracy.

i used this as given below

bg.BackgroundGeolocation.onMotionChange((bg.Location location) {
    if (location.isMoving) {
      print('[MotionChange] - User started moving');
    } else {
      print('[MotionChange] - User stopped moving (stationary)');
    }
  });

    // Start tracking (if not already)
    bg.BackgroundGeolocation.ready(bg.Config(
      desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
      distanceFilter: 10,
      stopOnTerminate: false,
      startOnBoot: true,
      stationaryRadius: 25,      // meters
      stopTimeout: 5,
      debug: false,
      logLevel: bg.Config.LOG_LEVEL_OFF,
    )).then((bg.State state) {
      if (!state.enabled) {
        bg.BackgroundGeolocation.start();
      }
    });

how to optimize battery usages with high location accuracy .

[Optional] Plugin Code and/or Config

bg.BackgroundGeolocation.onMotionChange((bg.Location location) {
        if (location.isMoving) {
          print('[MotionChange] - User started moving');
        } else {
          print('[MotionChange] - User stopped moving (stationary)');
        }
      });

        // Start tracking (if not already)
        bg.BackgroundGeolocation.ready(bg.Config(
          desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
          distanceFilter: 10,
          stopOnTerminate: false,
          startOnBoot: true,
          stationaryRadius: 25,      // meters
          stopTimeout: 5,
          debug: false,
          logLevel: bg.Config.LOG_LEVEL_OFF,
        )).then((bg.State state) {
          if (!state.enabled) {
            bg.BackgroundGeolocation.start();
          }
        });

[Optional] Relevant log output

@christocracy
Copy link
Member

Are you only using geofences?

@NishantTpm
Copy link
Author

Are you only using geofences?

Yes, I am using geofences to determine if the user is within the working area for attendance purposes.

I don't want to compromise on either geofence accuracy or battery optimization.

@christocracy
Copy link
Member

See api docs .startGeofences

@NishantTpm
Copy link
Author

Your package api docs mentions a reliable geofence radius of 200 meters. In our case , we want to apply 100-meter radius for geofence. it will still work reliably at this radius or not?

@christocracy
Copy link
Member

The radius minimum is imposed by the OS. You can try 100, but the OS will respond with its own minimum.

If you want a smaller radius, you could try using Polygon Geofences (sold separately: see api docs Geofences.vertices for more info)

@NishantTpm
Copy link
Author

ok

@NishantTpm
Copy link
Author

NishantTpm commented May 14, 2025

is this code is correct to use with the highest accuracy and best battery performance, using a 100-meter radius and a 10-meter distance filter.

Basically i want to track a device if the device is 100 m away from there base location then i want to perform some task.
if the device is enter then also perform some task.
And also want to use some motion detection feature of your package to save my battery life with highest location accuracy .

Please give the solution with code

this is how i use your package:

bg.BackgroundGeolocation.onMotionChange((bg.Location location) {
if (location.isMoving) {
print('[MotionChange] - User started moving');
} else {
print('[MotionChange] - User stopped moving (stationary)');
}
});

    // Start tracking (if not already)
    bg.BackgroundGeolocation.ready(bg.Config(
      desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
      distanceFilter: 10,
      stopOnTerminate: false,
      startOnBoot: true,
      stationaryRadius: 25,     
      stopTimeout: 5,
      debug: false,
      logLevel: bg.Config.LOG_LEVEL_OFF,
    )).then((bg.State state) {
      if (!state.enabled) {
        bg.BackgroundGeolocation.start();
      }
    });

@christocracy
Copy link
Member

yes

@NishantTpm
Copy link
Author

I want to know the best approach to prevent my mobile battery from draining quickly when using foreground and background services for location tracking. Please explain and provide a code example.

@christocracy
Copy link
Member

It’s not complicated. This plug-in consumes just as much energy as Google Maps does while following driving-directions.
The way this plug-in saves energy is by intelligently turning on location-tracking only when the device is moving and OFF when detected to be stationary.

Http requests consumes more energy/second than GPS. Decrease the number of http requests you do with a higher distanceFilter.

@NishantTpm
Copy link
Author

I want to test your plugin on a real device. It seems that the plugin only works in debug mode when using without license key.

I built the APK using the following command:
flutter build apk --debug

Then I installed the APK from this path:
C:\Users\Nk\Desktop\my-app\build\app\outputs\flutter-apk\app-debug.apk

However, the background services do not work when I install and run the app from this APK on a real device. But when I run the app directly on the device using a USB cable (via flutter run), the background services work as expected.

Could you please help me understand why the background services aren’t working with the installed debug APK and how to resolve this?

this is any problem with the code
bg.BackgroundGeolocation.ready(bg.Config(
desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
distanceFilter: 10,
stationaryRadius: 75,
stopTimeout: 5,
stopOnTerminate: false,
startOnBoot: false,
debug: true,
logLevel: bg.Config.LOG_LEVEL_OFF,
notification: bg.Notification(
title: "Location Tracking Started",
text: "We’re tracking your location for accuracy.",
channelName: "Location Service",
smallIcon: "mipmap/ic_launcher",
color: "#FF5722",
priority: bg.Config.NOTIFICATION_PRIORITY_HIGH,
)
)).then((bg.State state) {
if (!state.enabled) {
bg.BackgroundGeolocation.start();
}
});

@christocracy
Copy link
Member

Could you please help me understand why the background services aren’t working with the installed debug APK and how to resolve this?

The first thing I’d do is observe the logs from $ adb logcat.

See wiki “Debugging”.

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