fixed position error and added goad condition button

This commit is contained in:
2024-03-05 19:32:42 +05:30
parent 773650be82
commit 2f329669e9
4 changed files with 71 additions and 52 deletions

View File

@ -562,19 +562,24 @@ class DestinationController extends GetxController {
} }
Future<void> addGPStoDB(double la, double ln, {isCheckin = 0}) async { Future<void> addGPStoDB(double la, double ln, {isCheckin = 0}) async {
GpsDatabaseHelper db = GpsDatabaseHelper.instance; //print("in addGPStoDB ${indexController.currentUser}");
final team_name = indexController.currentUser[0]["user"]['team_name']; try {
final event_code = indexController.currentUser[0]["user"]["event_code"]; GpsDatabaseHelper db = GpsDatabaseHelper.instance;
GpsData gps_data = GpsData( final team_name = indexController.currentUser[0]["user"]['team_name'];
id: 0, final event_code = indexController.currentUser[0]["user"]["event_code"];
team_name: team_name, GpsData gps_data = GpsData(
event_code: event_code, id: 0,
lat: la, team_name: team_name,
lon: ln, event_code: event_code,
is_checkin: isCheckin, lat: la,
created_at: DateTime.now().millisecondsSinceEpoch); lon: ln,
var res = await db.insertGps(gps_data); is_checkin: isCheckin,
//print("==gps res == ${res}"); created_at: DateTime.now().millisecondsSinceEpoch);
var res = await db.insertGps(gps_data);
} catch (err) {
print("errr ready gps ${err}");
return;
}
} }
Future<void> checkForCheckin() async { Future<void> checkForCheckin() async {
@ -762,33 +767,38 @@ class DestinationController extends GetxController {
} }
void handleLocationUpdate(Position? position) async { void handleLocationUpdate(Position? position) async {
if (position != null) { try {
if (distanceToStart() >= 1000) { if (position != null) {
ready_for_goal = true; if (distanceToStart() >= 1000) {
} ready_for_goal = true;
}
var distance = const Distance(); var distance = const Distance();
double distanceToDest = distance.as( double distanceToDest = distance.as(
LengthUnit.Meter, LengthUnit.Meter,
LatLng(position.latitude, position.longitude), LatLng(position.latitude, position.longitude),
LatLng(currentLat, currentLon)); 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}");
LogManager().addLog( Duration difference =
"GPS : $currentLat, $currentLon - ${DateTime.now().hour}:${DateTime.now().minute}:${DateTime.now().second}:${DateTime.now().microsecond}"); 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}");
if (isInRog.value) { LogManager().addLog(
await addGPStoDB(position.latitude, position.longitude); "GPS : $currentLat, $currentLon - ${DateTime.now().hour}:${DateTime.now().minute}:${DateTime.now().second}:${DateTime.now().microsecond}");
lastGPSCollectedTime = DateTime.now(); if (isInRog.value) {
await addGPStoDB(position.latitude, position.longitude);
lastGPSCollectedTime = DateTime.now();
}
} }
} }
} finally {
currentLat = position.latitude; if (position != null &&
currentLon = position.longitude; (position.latitude != 0 || position.longitude != 0)) {
currentLat = position.latitude;
currentLon = position.longitude;
}
} }
} }
@ -908,7 +918,10 @@ class DestinationController extends GetxController {
} }
void centerMapToCurrentLocation() { void centerMapToCurrentLocation() {
indexController.mapController.move(LatLng(currentLat, currentLon), 17.0); print("center is ${currentLat}, ${currentLon}");
if (currentLat != 0 || currentLon != 0) {
indexController.mapController.move(LatLng(currentLat, currentLon), 17.0);
}
} }
void connectionChanged(String val) { void connectionChanged(String val) {

View File

@ -44,20 +44,26 @@ class GpsDatabaseHelper {
} }
Future<int> insertGps(GpsData gps) async { Future<int> insertGps(GpsData gps) async {
Database db = await instance.database; try {
int? nextOrder = print("---- try insering ${gps.toMap()}");
Sqflite.firstIntValue(await db.rawQuery('SELECT MAX(id) FROM gps')); Database db = await instance.database;
nextOrder = nextOrder ?? 0; int? nextOrder =
nextOrder = nextOrder + 1; Sqflite.firstIntValue(await db.rawQuery('SELECT MAX(id) FROM gps'));
gps.id = nextOrder; nextOrder = nextOrder ?? 0;
//print("---- insering ${gps.toMap()}"); nextOrder = nextOrder + 1;
int res = await db.insert( gps.id = nextOrder;
'gps', print("---- insering ${gps.toMap()}");
gps.toMap(), int res = await db.insert(
conflictAlgorithm: ConflictAlgorithm.replace, 'gps',
); gps.toMap(),
//print("------ database helper insert $res-----------::::::::"); conflictAlgorithm: ConflictAlgorithm.replace,
return res; );
print("------ database helper insert $res-----------::::::::");
return res;
} catch (err) {
print("------ error $err-----------::::::::");
return -1;
}
} }
Future<List<GpsData>> getGPSData(String team_name, String event_code) async { Future<List<GpsData>> getGPSData(String team_name, String event_code) async {

View File

@ -129,7 +129,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
style: ElevatedButton.styleFrom(backgroundColor: Colors.red), style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
onPressed: destinationController.rogainingCounted.value == true && onPressed: destinationController.rogainingCounted.value == true &&
destinationController.distanceToStart() <= 500 && destinationController.distanceToStart() <= 500 &&
//destination.cp == -1 && destination.cp == -1 &&
DestinationController.ready_for_goal == true DestinationController.ready_for_goal == true
? () async { ? () async {
destinationController.isAtGoal.value = true; destinationController.isAtGoal.value = true;

View File

@ -176,7 +176,7 @@ class _MapWidgetState extends State<MapWidget> {
} }
void _centerMapOnUser() { void _centerMapOnUser() {
print("showBottomSheet ${destinationController.shouldShowBottomSheet}"); //print("showBottomSheet ${destinationController.shouldShowBottomSheet}");
if (destinationController.shouldShowBottomSheet) { if (destinationController.shouldShowBottomSheet) {
destinationController.centerMapToCurrentLocation(); destinationController.centerMapToCurrentLocation();
} }