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
//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"];

View File

@ -498,6 +498,8 @@ class BottomSheetNew extends GetView<BottomSheetController> {
// ),
destinationController.rogainingCounted.value == true &&
destinationController.distanceToStart() <=
500 &&
destination.cp == -1
? ElevatedButton(
onPressed: () async {
@ -604,10 +606,14 @@ class BottomSheetNew extends GetView<BottomSheetController> {
),
// forced start / checkin
Obx(() => ElevatedButton(
distanceToDest <=
destinationController
.getForcedChckinDistance(destination)
? Obx(() => ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor:
Theme.of(context).colorScheme.secondary),
backgroundColor: Theme.of(context)
.colorScheme
.secondary),
onPressed: () async {
//print("~~~~ manual checkin button ~~~~");
if (destination.cp == -1 &&
@ -636,7 +642,8 @@ class BottomSheetNew extends GetView<BottomSheetController> {
},
child: Text(
destination.cp == -1 &&
destinationController.isInRog.value ==
destinationController
.isInRog.value ==
false &&
destinationController
.rogainingCounted.value ==
@ -653,8 +660,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
color: Theme.of(context)
.colorScheme
.onSecondary))))
// ElevatedButton(
// onPressed: () {}, child: const Text("ゲーム中")),
: Container(),
],
),
Row(