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

Adding the proper setup for a metered ride. #1393

Open
oumarhadrami opened this issue Dec 15, 2024 · 3 comments
Open

Adding the proper setup for a metered ride. #1393

oumarhadrami opened this issue Dec 15, 2024 · 3 comments

Comments

@oumarhadrami
Copy link

Your Environment

  • Plugin version: flutter_background_geolocation: ^4.16.3
  • Platform: Android
  • OS version: 11 to 14
  • Device manufacturer / model: General
  • Flutter info (flutter doctor):
$ flutter doctor                
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.3, on Ubuntu 24.04.1 LTS 6.8.0-50-generic, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2023.2)
[✓] VS Code (version 1.95.3)
[✓] Connected device (2 available)
[✓] Network resources

• No issues found!
  • Plugin config:
bg.Config bgConfig() {
  return bg.Config(
    enableHeadless: true,
    stopOnTerminate: false,
    startOnBoot: true,
    distanceFilter: 50,
    minimumActivityRecognitionConfidence: 50,
    stopTimeout: 12,
    isMoving: true,
    stopOnStationary: false,
    desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
    logLevel: bg.Config.LOG_LEVEL_INFO,
    logMaxDays: 1,
    disableElasticity: true,
    foregroundService: true,
    reset: false,
    debug: false,
    backgroundPermissionRationale: bg.PermissionRationale(
      title: 'bg_title'.tr,
      message: 'bg_message'.tr,
      positiveAction: 'bg_positiveAction'.tr,
      negativeAction: 'bg_negativeAction'.tr,
    ),
    notification: bg.Notification(
      title: Constants.appName,
      text: '${Constants.appName} Partner',
    ),
  );
}

Expected Behavior

So we want to optimize the plugin on android devices so that when the device is stopped, we get notified as soon as possible and when it's moving, we get position every 50 meters. The price is calculated from number of meters traveled plus the time being spent on stationary mode. The plugin can do this I believe from my research on it. The calculation can be done on the device itself or the server. What is the design or setup to do this in efficient way using the plugin?

Actual Behavior

This is more of setup recommendation to achieve the objective.

Context

So we want to optimize the plugin on android devices so that when the device is stopped, we get notified as soon as possible and when it's moving, we get position every 50 meters. The price is calculated from number of meters traveled plus the time being spent on stationary mode. The plugin can do this I believe from my research on it. The calculation can be done on the device itself or the server. What is the design or setup to do this in efficient way using the plugin?

@christocracy
Copy link
Member

See API docs event .onMotionChange. Also see Config.stopTimeout.

@oumarhadrami
Copy link
Author

While trying this and getting a better idea of the plugin capability, I concluded the need for the testing server you provided to check the uploaded locations.
I tried simplifying the test by cloning console repo, installed the modules with npm install, started the server with npm start without providing any environment variables other than Google Maps API and the web app opened on port 9000 just fine. I opened another terminal to run npm test while the server is running and showed

$ npm test

> [email protected] test
> jest

 PASS  tests/site-api.test.js
 PASS  tests/api.test.js
 FAIL  tests/firebase.test.js
  ● Test suite failed to run

    Your test suite must contain at least one test.

      at onResult (node_modules/@jest/core/build/TestScheduler.js:175:18)
      at node_modules/@jest/core/build/TestScheduler.js:304:17
      at node_modules/emittery/index.js:260:13
          at Array.map (<anonymous>)
      at Emittery.Typed.emit (node_modules/emittery/index.js:258:23)

Test Suites: 1 failed, 2 passed, 3 total
Tests:       29 passed, 29 total
Snapshots:   0 total
Time:        1.344 s
Ran all test suites.

I went to to my flutter app and finalized the config:

final deviceParams = await bg.Config.deviceParams;
  return bg.Config(
    url: 'http://192.168.100.249:9000/locations',
    params: deviceParams,
    enableHeadless: true,
    stopOnTerminate: false,
    startOnBoot: true,
    distanceFilter: 0,
    minimumActivityRecognitionConfidence: 50,
    stopTimeout: 12,
    stopOnStationary: false,
    allowIdenticalLocations: true,
    locationUpdateInterval: 5000,
    desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
    logLevel: !['prod'].contains(appFlavor)
        ? bg.Config.LOG_LEVEL_VERBOSE
        : bg.Config.LOG_LEVEL_ERROR,
    logMaxDays: 1,
    disableElasticity: true,
    foregroundService: true,
    reset: !['prod'].contains(appFlavor),
    debug: !['prod'].contains(appFlavor),
    backgroundPermissionRationale: bg.PermissionRationale(
      title: 'bg_title'.tr,
      message: 'bg_message'.tr,
      positiveAction: 'bg_positiveAction'.tr,
      negativeAction: 'bg_negativeAction'.tr,
    ),
    notification: bg.Notification(
      title: Constants.appName,
      text: '${Constants.appName} Partner',
    ),
  );

However the web console shows no new device other than the default iphone 10 flutter device. shows no locations. Have I done this wrong?

@christocracy
Copy link
Member

If you can’t get your own clone of the demo server to work, just use my deployed version at https://tracker.transistorsoft.com.

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