Home > database >  How to get location every 10 sec using flutter
How to get location every 10 sec using flutter

Time:11-22

I am very new to flutter. I have to make an app that send the device location every 10 seconds, even if app is minimised and gets killed by the user. After that data i have to make a socket connection and a http post if(socket fails).

The app should must work with both Android and IOS. Is it possible to do in flutter?

CodePudding user response:

You would subscribe to a Location-Stream, for example using this package:

https://pub.dev/packages/geolocator

Using a period-timer you would push the location to a server-side service. This should work in Fore- and Background-state.

But measuring location for "terminated" apps is a lot more difficult. You need to install some kind of persistent background service.

This plugin may give you some answers:

https://pub.dev/packages/flutter_background_geolocation

CodePudding user response:

background locator 2: https://pub.dev/packages/background_locator_2 Android works. The problem is that the time values are slightly random The value is delivered well within 10 seconds when the app is closed. However, if the app is turned off for a long time, due to the nature of Android, it is forcibly switched to sleep mode, so the return value is slightly random.

iPhone works fine

background_geolocation works well instead of being paid https://pub.dev/packages/flutter_background_geolocation

  • Related