flutter-geolocator
flutter-geolocator copied to clipboard
Add support for background location tracking
Also see: https://github.com/flutter/plugins/pull/656
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!
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.
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.
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
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.
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.
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.
Guys, any update on this? This feature can add wings to this plugin. It is must needed.
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.
@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.
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).
@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...
Hope you guys can add BG service soon :)
Hi! What is the current status of this issue? is someone working on it? or has been postponed?
Hey guys what are your thoughts on https://pub.dartlang.org/packages/flutter_background_geolocation Doesn't this plugin provide what is asked here?
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+
See this article https://medium.com/flutter-io/executing-dart-in-the-background-with-flutter-plugins-and-geofencing-2b3e40a1a124
@christocracy, I think your package is worth every cent however I'm just too poor atm :) Watching this space
hi there is it possible to track live location @christocracy free?
Looking forward to this!
Do you think it will be possible to start work on in it in this year?
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.
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 ;)
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.
- 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
- To use Foreground service you need to show system notification. Probably every application will want to have customized notification.
- Compatibility with iOS. Geolocator API should hide differences between platform as much as possible.
- 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_managerplugin. 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.
I hope google would add this feature in flutter out of the box :p
Hello, is this issue closed? I need the background geolocation too for android and ios for flutter! Which is the best lib for this?
Just to add my +1 to this feature request. For some applications this is a showstopper. Would be amazing to have it.
+1 Would be so helpful for so many applications
This is highly needed in my project... I was impressed by the one I found on pub, but 300USD?
I was also facing this issue and I developed my own plugin for background location updates, here it is, flutter_background_location ,