Flutter || How to update location while the app running in the background

Viewed 466

How I can get longitude and latitude from carp_background_location.

This is the outcome in the terminal:-

sendLocationEvent {callback=5839465806, location={altitude=78.0, heading=67.55118, latitude=30.2145618, accuracy=9.648, speed_accuracy=0.16278821, time=1.645010177E12, is_mocked=false, speed=0.0027909183, longitude=71.4721748}}

3 Answers

You can get the location of the user but google will prevent you to do that because of "privacy and policy rules", but it will be a battery drainer application. Apps like uber , they use GPS while the app still running in the background

If you just want it to be fetched when the app is in the background (not killed state) then you can simply use Timer.periodic() and as the callback function, you can pass the function to fetch location.

However, it also depends on the OS when to kill the app. For example, if your app is consuming a lot of resources, OS can kill your app.

geolocator: ^8.2.0

this package can get a location in background just add permissions

Related