update gps collection time and distance

This commit is contained in:
2023-11-28 11:48:31 +05:30
parent 44cb728fab
commit 6f084b2349
2 changed files with 75 additions and 52 deletions

View File

@ -36,6 +36,7 @@ class DestinationController extends GetxController {
List<Destination> destinations = <Destination>[].obs;
double currentLat = 0.0;
double currentLon = 0.0;
DateTime lastGPSCollectedTime = DateTime.now();
static bool gps_push_started = false;
static bool game_started = false;
@ -524,9 +525,10 @@ class DestinationController extends GetxController {
try {
//print("--- 000 ---- $skip_gps----");
await Future.delayed(const Duration(milliseconds: 2500));
await Future.delayed(const Duration(milliseconds: 3000));
Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.bestForNavigation);
currentLat = position.latitude;
currentLon = position.longitude;
final la = position.latitude;
@ -535,7 +537,22 @@ class DestinationController extends GetxController {
//print("--- gps is ${la}, ${ln}");
//add gps to database
await addGPStoDB(la, ln);
//check distance to previous point
var distance = const Distance();
double distanceToDest = distance.as(
LengthUnit.Meter,
LatLng(position.latitude, position.longitude),
LatLng(currentLat, currentLon));
Duration difference =
lastGPSCollectedTime.difference(DateTime.now()).abs();
if (difference.inSeconds >= 10 || distanceToDest >= 10) {
print(
"^^^^^^^^ GPS data collected ${DateFormat('kk:mm:ss \n EEE d MMM').format(DateTime.now())}, ^^^ ${position.latitude}, ${position.longitude}");
await addGPStoDB(la, ln);
lastGPSCollectedTime = DateTime.now();
}
// GpsDatabaseHelper db = GpsDatabaseHelper.instance;
// final team_name = indexController.currentUser[0]["user"]['team_name'];
// final event_code = indexController.currentUser[0]["user"]["event_code"];