Reputation: 2790
I have developed an application in flutter to capture the coordinates. code below is capturing coordinates correctly but the problem is, it is not working when the application is closed. I need to capture the location even the app is closed.Any help will be appreciated
@override
void initState()
{
super.initState( );
BackgroundLocation.startLocationService( );
BackgroundLocation.getLocationUpdates( (location) async {
setState( () {
debugPrint(globals.sUserCode);
debugPrint(globals.sActiveTripCode);
this.latitude = location.latitude.toString( );
this.longitude = location.longitude.toString( );
this.accuracy = location.accuracy.toString( );
this.altitude = location.altitude.toString( );
this.bearing = location.bearing.toString( );
this.speed = location.speed.toString( );
this.time =
DateTime.fromMillisecondsSinceEpoch( location.time.toInt( ) )
.toString( );
} );
}
Upvotes: 1
Views: 5890
Reputation: 11
You can also consider this plugin which has a pretty generous free tier and additional geo APIs and tracking functionality included.
Upvotes: 1
Reputation: 44056
When your app is closed, the UI Isolate isn't running. You need to move your geo stuff to a second Isolate so it can continue to run. See what Google has to say about that: https://flutter.dev/docs/development/packages-and-plugins/background-processes
Upvotes: 2
Reputation: 1430
I used such a package in the project. But the package has a certain limitation. Paid for extra use. We tried all the ways you did. But it didn't happen. Either you have to write from scratch by ios and android. otherwise, you may have no other choice. We had no other choice but to buy this package because our time was limited. And it works just fine.
Upvotes: 2