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

How can i store locations even when device is not moving? #213

Closed
wemersonrv opened this issue Mar 30, 2020 · 16 comments
Closed

How can i store locations even when device is not moving? #213

wemersonrv opened this issue Mar 30, 2020 · 16 comments

Comments

@wemersonrv
Copy link

Your Environment

  • Plugin version: flutter_background_geolocation: ^1.7.1
  • Platform: iOS or Android
  • OS version: 8
  • Device manufacturer / model: Motorola Moto G 5
  • Flutter info (flutter doctor):

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [versão 10.0.17763.678], locale pt-BR)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[√] Android Studio (version 3.6)
[√] VS Code (version 1.43.2)
[√] Connected device (1 available)

  • Plugin config:
bg.Config(
        desiredAccuracy: bg.Config.DESIRED_ACCURACY_MEDIUM,
        logLevel: bg.Config.LOG_LEVEL_OFF,
        disableElasticity: true,
        distanceFilter: 10,
        stopOnTerminate: false,
        startOnBoot: true,
        heartbeatInterval: 300,
        minimumActivityRecognitionConfidence: 40,
        persistMode: bg.Config.PERSIST_MODE_LOCATION,
        allowIdenticalLocations: true,
        debug: debug,
        notification: bg.Notification(
          priority: bg.Config.NOTIFICATION_PRIORITY_MIN,
          text: 'Suas horas estão sendo registradas!',
        ),
        extras: {
          'user': user, // Email do usuário
        },
      )

Expected Behavior

Need to capture points even when device is not moving.

Actual Behavior

Get location only when users walks.

Steps to Reproduce

Context

I only need to detect the user's position every X minutes, even if the device is not moving.

Debug logs

Logs
PASTE_YOUR_LOGS_HERE
@christocracy
Copy link
Member

implement background_fetch callback. This plugin (also managed by Transistor Software) is already included as a dependency.

Execute BackgroundGeolocation.getCurrentPosition in your fetch callback.

@wemersonrv
Copy link
Author

implement background_fetch callback. This plugin (also managed by Transistor Software) is already included as a dependency.

Execute BackgroundGeolocation.getCurrentPosition in your fetch callback.

Just need to implement background_fetch to awake the app and run BackgroundGeolocation.getCurrentPosition ?

I was trying it on heartBeat but only works when app is working. Understand now.

One last question: We use Firestore. So need to buy license for flutter_background_geolocationand background_geolocation_firebase ?

@christocracy
Copy link
Member

christocracy commented Mar 30, 2020

One last question: We use Firestore. So need to buy license for flutter_background_geolocation and background_geolocation_firebase

Yes. The background_geolocation_firebase adapter is optional. You are, of course, free to manage your own firebase inserts using background-geolocation's onLocation event-handler in addition to a headless-task for the case where your Android app is terminated. It just a convenience adapter to make your life easier.

@wemersonrv
Copy link
Author

questions:

  1. Headeless task can work with a normal app? or only in apps without views? Works only on Android?
  2. background_fetch works with Android and IOS ?

@christocracy
Copy link
Member

Headeless task can work with a normal app?

Any Android app that has been terminated.

Works only on Android?

Yes, iOS has no such concept of running “headless”

@wemersonrv
Copy link
Author

Headeless task can work with a normal app?

Any Android app that has been terminated.

Works only on Android?

Yes, iOS has no such concept of running “headless”

Ok, and about background_fetch... solve the problem on both OS ?

@christocracy
Copy link
Member

christocracy commented Mar 30, 2020

Fetch has similar Android headless mechanism. If user terminates app, iOS stops firing fetch events. You absolutely have no ability to keep periodically requesting location when user explicitly terminates the iOS app.

However, the iOS background-geolocation plugin will automatically initiate location tracking in a terminated app when device moves about 200 meters.

@wemersonrv
Copy link
Author

So, i cannot make my app to IOS if i expect capture user home position, if app is closed?

@christocracy
Copy link
Member

So, i cannot make my app to IOS if i expect capture user home position, if app is closed?

If the iOS device is sitting stationary in the same place, correct. However, once the user moves ~200 meters, the background_geolocation plugin will cause the iOS app to automatically re-launch in the background and tracking will resume. Read the API docs for Config.stopOnTerminate.

@wemersonrv
Copy link
Author

Hello @christocracy . There is a thing i don't understan.

You told me here that when device became stationary, and app closes, i can use background_fetch to make periodic captures in Androi but not in iOS, because background_fetch uses headless android specific feature... Ok, i understand that.

But, in background_fetch pub.dev page, it has an iOS badge... So, did you found a way to implement it in ios too ??

@christocracy
Copy link
Member

Where did I tell you that?

@wemersonrv
Copy link
Author

wemersonrv commented May 13, 2020

Here..

If the iOS device is sitting stationary in the same place, correct.

After i ask about not works on ios, even with background_fetch.

@christocracy
Copy link
Member

Where did I say:

to make periodic captures in Androi but not in iOS

@wemersonrv
Copy link
Author

wemersonrv commented May 13, 2020

Where did I say:

to make periodic captures in Androi but not in iOS

I make a short resume about all stuffs we discuss here... just that... at least, as I understand it.

The point is:

Your plugin is amazing, far beyond others. This is a fact and I congratulate you for that

But, my solution needs to capture positions every 15 (or 30) minutes even when device is in a fixed position all day. In Android is fine with background_fetch but in ios only when user moves ~200 meters, so i do nout found how to implement it,.. and in our interactions here i understand that is not possible in ios.

@christocracy
Copy link
Member

christocracy commented May 13, 2020

iOS background_fetch will completely re-launch an app that was terminated by the os to service the event, just as if launched from the home-screen. However, If the user terminates the app, iOS halts fetch events. In that case, it’s impossible to do any time-based location tracking.

Sometimes, what you want on mobile (particularly iOS) is simply impossible.

@christocracy
Copy link
Member

Also for iOS background_fetch, if the user doesn’t open your app daily, iOS will halt fetch events.

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