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; List<Destination> destinations = <Destination>[].obs;
double currentLat = 0.0; double currentLat = 0.0;
double currentLon = 0.0; double currentLon = 0.0;
DateTime lastGPSCollectedTime = DateTime.now();
static bool gps_push_started = false; static bool gps_push_started = false;
static bool game_started = false; static bool game_started = false;
@ -524,9 +525,10 @@ class DestinationController extends GetxController {
try { try {
//print("--- 000 ---- $skip_gps----"); //print("--- 000 ---- $skip_gps----");
await Future.delayed(const Duration(milliseconds: 2500)); await Future.delayed(const Duration(milliseconds: 3000));
Position position = await Geolocator.getCurrentPosition( Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.bestForNavigation); desiredAccuracy: LocationAccuracy.bestForNavigation);
currentLat = position.latitude; currentLat = position.latitude;
currentLon = position.longitude; currentLon = position.longitude;
final la = position.latitude; final la = position.latitude;
@ -535,7 +537,22 @@ class DestinationController extends GetxController {
//print("--- gps is ${la}, ${ln}"); //print("--- gps is ${la}, ${ln}");
//add gps to database //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; // GpsDatabaseHelper db = GpsDatabaseHelper.instance;
// final team_name = indexController.currentUser[0]["user"]['team_name']; // final team_name = indexController.currentUser[0]["user"]['team_name'];
// final event_code = indexController.currentUser[0]["user"]["event_code"]; // 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.rogainingCounted.value == true &&
destinationController.distanceToStart() <=
500 &&
destination.cp == -1 destination.cp == -1
? ElevatedButton( ? ElevatedButton(
onPressed: () async { onPressed: () async {
@ -604,57 +606,61 @@ class BottomSheetNew extends GetView<BottomSheetController> {
), ),
// forced start / checkin // forced start / checkin
Obx(() => ElevatedButton( distanceToDest <=
style: ElevatedButton.styleFrom( destinationController
backgroundColor: .getForcedChckinDistance(destination)
Theme.of(context).colorScheme.secondary), ? Obx(() => ElevatedButton(
onPressed: () async { style: ElevatedButton.styleFrom(
//print("~~~~ manual checkin button ~~~~"); backgroundColor: Theme.of(context)
if (destination.cp == -1 &&
destinationController.isInRog.value ==
false &&
destinationController
.rogainingCounted.value ==
false) {
destinationController.isInRog.value = true;
destinationController.addToRogaining(
destinationController.currentLat,
destinationController.currentLon,
destination.location_id!);
saveGameState();
ExternalService()
.startRogaining()
.then((value) => Get.back());
} else {
if (destination.cp == -1) {
return;
}
Get.back();
await destinationController
.callforCheckin(destination);
}
},
child: Text(
destination.cp == -1 &&
destinationController.isInRog.value ==
false &&
destinationController
.rogainingCounted.value ==
false
? "ロゲ開始"
: destinationController.isInRog.value ==
true &&
destination.cp == -1
? "ゲーム中"
: isAlreadyCheckedIn == true
? "ゲーム中"
: "チェックイン",
style: TextStyle(
color: Theme.of(context)
.colorScheme .colorScheme
.onSecondary)))) .secondary),
// ElevatedButton( onPressed: () async {
// onPressed: () {}, child: const Text("ゲーム中")), //print("~~~~ manual checkin button ~~~~");
if (destination.cp == -1 &&
destinationController.isInRog.value ==
false &&
destinationController
.rogainingCounted.value ==
false) {
destinationController.isInRog.value = true;
destinationController.addToRogaining(
destinationController.currentLat,
destinationController.currentLon,
destination.location_id!);
saveGameState();
ExternalService()
.startRogaining()
.then((value) => Get.back());
} else {
if (destination.cp == -1) {
return;
}
Get.back();
await destinationController
.callforCheckin(destination);
}
},
child: Text(
destination.cp == -1 &&
destinationController
.isInRog.value ==
false &&
destinationController
.rogainingCounted.value ==
false
? "ロゲ開始"
: destinationController.isInRog.value ==
true &&
destination.cp == -1
? "ゲーム中"
: isAlreadyCheckedIn == true
? "ゲーム中"
: "チェックイン",
style: TextStyle(
color: Theme.of(context)
.colorScheme
.onSecondary))))
: Container(),
], ],
), ),
Row( Row(