Baseflow / flutter-geolocator

Android and iOS Geolocation plugin for Flutter
https://baseflow.com/
MIT License
1.24k stars 654 forks source link

Add support for background location tracking #53

Open martijn00 opened 6 years ago

martijn00 commented 6 years ago

Also see: https://github.com/flutter/plugins/pull/656

eliashdezr commented 6 years ago

This is one of the main reasons I haven't switch one of my apps to Flutter, background location tracking is a must. Thanks for keeping this on track!

aidandavis commented 6 years ago

I'm also looking into this. Wanting to build an app in a corporate setting with a background GPS tracking requirement. flutter/plugins#656 (mentioned above) isn't on Pub yet and only supports iOS. I'll subscribe to this thread for any updates.

aidandavis commented 6 years ago

I ended up writing my own implementation (on Android, at least), based off this Google sample that runs when the app closes.

I'm pushing the location data to firebase, so I didn't need to send anything back up the method channel. I just upload straight to Firebase using native code when a location result arrives. This means I can't generalise it to help this plugin out, but that sample repo might be useful.

velegip commented 6 years ago

I found a solution to generalize your @aidandavis method. In this packege all locations stored in sqlite. If your foreground service can accept store provider sqlite/firebase/... . With MethodChannel we can get the db file location, and the flutter app can read it.

Update: The Google sample not prevent Doze Mode. If the device uses doze the network and the gps can be killed with your service too.

Update 2: This stackoverflow thread help against chinese roms battery saving things, and adds app to protected list. This against Doze

aidandavis commented 6 years ago

That's definitely a way to do it. The problem still remaining is doing something with the data while the app is in background or the sytem chooses to close it.

With regards to Doze, it should only apply when the phone is stationary (like on a table). There's no point tracking location updates at that point anyway - the last location sent prior to Doze would still be accurate.

sestegra commented 6 years ago

On top of this, Dart code could be embedded as the same way implemented in alarm_manager_android. The Android callback calls Dart code without the app running.

JesseRMeyer commented 6 years ago

I see that this feature was removed from the 2.1.0 milestone. Has it been pushed to the back burner? My project also would greatly benefit from this.

dark-chocolate commented 5 years ago

Guys, any update on this? This feature can add wings to this plugin. It is must needed.

ibrierley commented 5 years ago

It's maybe also worth noting that some devices can't get gps locations with the screen off. I've been stuck on this one for a while, and finally found it's down to the devices chipset. So it may be worth double checking that as well, especially if it's a low battery device like a watch.

dark-chocolate commented 5 years ago

@ibrierley I am not sure about the wearables but all the devices (Mobile/Tablets) running API >= 16 are capable of getting location updates even when the screen is off. I tested that myself too.

ibrierley commented 5 years ago

Yes, I've mainly been testing on a Huawei watch 2, and read a thread where there was a post with I think a Huawei engineer (may be wrong), saying it was set in the chipset, so they couldn't fix it (I'll post here if I can find the thread, but haven't seen it on a quick search).

I've ended up turning the screen black, but I hate that solution :) (but it works, just not quite sure if it saves that much battery, so may end up forcing the screen on with something displaying).

angel1st commented 5 years ago

@martijn00 I wonder if Geofence plugin won't give a boost on this feature. I believe background execution would be a crucial one and many of us are expecting it. Let me know what do you think...

ashihCT commented 5 years ago

Hope you guys can add BG service soon :)

kocholes commented 5 years ago

Hi! What is the current status of this issue? is someone working on it? or has been postponed?

lambasoft commented 5 years ago

Hey guys what are your thoughts on https://pub.dartlang.org/packages/flutter_background_geolocation Doesn't this plugin provide what is asked here?

kostiaalyo commented 5 years ago

Hey guys what are your thoughts on https://pub.dartlang.org/packages/flutter_background_geolocation Doesn't this plugin provide what is asked here?

It does, but it costs $300+

akinsete commented 5 years ago

See this article https://medium.com/flutter-io/executing-dart-in-the-background-with-flutter-plugins-and-geofencing-2b3e40a1a124

gregology commented 5 years ago

@christocracy, I think your package is worth every cent however I'm just too poor atm :) Watching this space

vishweshsoni commented 5 years ago

hi there is it possible to track live location @christocracy free?

nikoskip commented 5 years ago

Looking forward to this!

mateuszmatyszkowicz commented 5 years ago

Do you think it will be possible to start work on in it in this year?

audkar commented 5 years ago

Do you think it will be possible to start work on in it in this year?

Anyone can start working immediately. Contributions are welcome.

Maintainers of this project does quite good job on accepting incoming changes from community.

mateuszmatyszkowicz commented 5 years ago

Ok, gimmie resources, and place in code where to start and I try to do my best :D I could spend few weeks to solve it but firstly I need to get in to android deeper :( , I'm just curios if someone is working on it ;)

audkar commented 5 years ago

I appreciate your enthusiasm :1st_place_medal:

gimmie resources, and place in code where to start

I believe that you will have to touch and understand this whole plugin.


However... Few high level design problems should considered before you start coding.

  1. On android newer Android (API 26) only way to get high precision location updates is using Foreground service. Latest (Android Q) also will have additional permission (for getting location in background). So need to address 3 different behavior to have compatibility for: android pre 26, android 26 and android Q
  2. To use Foreground service you need to show system notification. Probably every application will want to have customized notification.
  3. Compatibility with iOS. Geolocator API should hide differences between platform as much as possible.
  4. Foreground Service can be stopped & restarted same as Activity. Need logic to handle this. Flutter doesn't have easy way to do this. Only example I know is alarm_manager plugin. But it buggy as well and doesn't handle all cases. I don't know any open source Flutter library which does this correctly.

For our case we need to track more data for long periods of time (location, bluetooth, sensors). So making every plugin handle long running logic separately is not suitable for use because every plugin would have separate Foreground service and user would see three different Notifications.

lambasoft commented 5 years ago

I hope google would add this feature in flutter out of the box :p

nsmith1024 commented 5 years ago

Hello, is this issue closed? I need the background geolocation too for android and ios for flutter! Which is the best lib for this?

moovida commented 5 years ago

Just to add my +1 to this feature request. For some applications this is a showstopper. Would be amazing to have it.

Martibis commented 5 years ago

+1 Would be so helpful for so many applications

Kelvinkins commented 5 years ago

This is highly needed in my project... I was impressed by the one I found on pub, but 300USD?

Shahxad-Akram commented 5 years ago

I was also facing this issue and I developed my own plugin for background location updates, here it is, flutter_background_location ,

milesgranger commented 5 years ago

+1 Also looking forward to this.

Zeissus commented 5 years ago

+1 This is very much needed!

shishirraven commented 5 years ago
shishirraven commented 5 years ago
dark-chocolate commented 5 years ago

@milesgranger @Zeissus @shishirraven and others

If you have this issue, instead of writing +1 in comment, give a thumbs up to the issue, it makes more sense.

christocracy commented 5 years ago

@AlexCampos95 Why don't you ask me at my repo?

lyseiha commented 4 years ago

Any solution yet?

Slaheddine commented 4 years ago

any solution ?

fhamborg commented 4 years ago

any?

akinsete commented 4 years ago

Don't know if this is helpful, was working on this some months ago. https://github.com/akinsete/Flutter-Background-Location-Service

Try it out.

On Thu, Dec 12, 2019 at 12:05 PM Felix Hamborg notifications@github.com wrote:

any?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Baseflow/flutter-geolocator/issues/53?email_source=notifications&email_token=AFKOFXJ2RA2FV2Q6LBZBUXTQYKDNZA5CNFSM4FM72VCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGXV2AQ#issuecomment-565140738, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFKOFXLSVIXG74CNIBXLPQDQYKDNZANCNFSM4FM72VCA .

estevez-dev commented 4 years ago

The only thing that really works for me is workmanager + geolocator. If battery saving will be disabled for your app, this will work constantly even after phone restart.

akinsete commented 4 years ago

Hi, Yegor Vialov

This seems like a good idea. Do you have a sample project that implement both for background location monitoring? If you do can you please share.

Thanks

On Fri, Dec 13, 2019 at 1:52 AM Yegor Vialov notifications@github.com wrote:

The only thing that really works for me is workmanager https://pub.dev/packages/workmanager + geolocator https://pub.dev/packages/geolocator. If battery saving will be disabled for your app, this will work constantly even after phone restart.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Baseflow/flutter-geolocator/issues/53?email_source=notifications&email_token=AFKOFXJ3L4B6SVPCWOUYBLLQYNENLA5CNFSM4FM72VCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGZKOXY#issuecomment-565356383, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFKOFXOP3K36MV6LCE3E7HTQYNENLANCNFSM4FM72VCA .

estevez-dev commented 4 years ago

@akinsete , HA Client: https://github.com/estevez-dev/ha_client

MazEbeid commented 4 years ago

Workmanager is inconsistent in iOS you dont have any control over when a task would run so it wont work for realtime location updates purposes. On Android the minimum frequency is 15mins so this doesnt work as well.

We really need this to be implemented in flutter out of the box.

ZM123 commented 4 years ago

I don't have a lot of experience with Android, but it looks like there's a separate call for background location updates compared to foreground ones (which is the one that is currently used in this plugin). Not sure how it would work but I imagine we would want to somehow use the optimal function based on which state the app is in.

Are there any other updates on this? This is a pretty key feature for a location tracking package and would be really nice to have if this is to be the number 1 location package for flutter

jamesdixon commented 4 years ago

@christocracy 's plugin is well worth the money and he responds very, very quickly. If background location is important to your application, it's a nominal cost.

pavel-birdy commented 4 years ago

@jamesdixon that library is great. But I have a task manager app where tasks have location notification. Using geolocator + flutter_local_notifications I can trigger push notification when the app is foreground but doesn't work when the app goes background. flutter_background_geolocation is too much for my requirement.

RomanJos commented 4 years ago

Maybe this lib can help you: https://github.com/rekab-app/background_locator

Maaaaan you find a gem here its EXACTLY what I need the only problem is that it lack documentation

steinmetz commented 4 years ago

Maybe this lib can help you: https://github.com/rekab-app/background_locator

Maaaaan you find a gem here its EXACTLY what I need the only problem is that it lack documentation

I managed to execute their example... It works ok, sometimes it seems that it stops recording the coordinates when I close the main app and it executes the service in background.. But I have to test it again...

Let me know if you need help to execute it :)

RomanJos commented 4 years ago

It work well for me the only problem is to save on disk in the callback function, the service don't register the plugins native code and thus I can't make native calls using path_provider for example, also if the app is killed the Isolate will send to the ReceivePort from the killed FlutterActivity so nothing is listening. On restart I need to kill the isolate and then recreate it using a new port but I don't think its the best solution lol. I also found this example that is quite similar to what the library do (have a service that execute dart code with a notification) but they register the plugins entry in the Kotlin file so they are able to store things on the disk If you know how I can retrieve the LatLng from the callback function it would be awesome🙏