changed GPS listener

This commit is contained in:
2023-12-07 10:20:44 +05:30
parent fa0587178f
commit 56c07852f9
7 changed files with 70 additions and 69 deletions

View File

@ -21,6 +21,7 @@ import 'package:rogapp/services/maxtrix_service.dart';
import 'package:rogapp/services/perfecture_service.dart';
import 'package:rogapp/utils/database_gps.dart';
import 'package:rogapp/utils/database_helper.dart';
import 'package:rogapp/utils/location_controller.dart';
import 'package:rogapp/widgets/bottom_sheet_new.dart';
import 'dart:async';
@ -72,6 +73,7 @@ class DestinationController extends GetxController {
final photos = <File>[].obs;
final IndexController indexController = Get.find<IndexController>();
final LocationController locationController = Get.put(LocationController());
int _start = 0;
int chekcs = 0;
@ -523,54 +525,10 @@ class DestinationController extends GetxController {
Future<void> checkForCheckin() async {
//print("--- Start of checkForCheckin function ---");
await Future.delayed(const Duration(milliseconds: 3000));
game_started = true;
try {
//print("--- 000 ---- $skip_gps----");
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;
final ln = position.longitude;
LogManager().addLog(
"GPS : $currentLat, $currentLon - ${DateTime.now().hour}:${DateTime.now().minute}:${DateTime.now().second}:${DateTime.now().microsecond}");
//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"];
// print("--- curr gps is ${la}, ${ln}");
// GpsData gps_data = GpsData(
// id: 0,
// team_name: team_name,
// event_code: event_code,
// lat: la,
// lon: ln,
// created_at: DateTime.now().microsecondsSinceEpoch);
// await db.insertGps(gps_data);
indexController.locations[0].features.forEach((fs) async {
GeoJSONMultiPoint mp = fs!.geometry as GeoJSONMultiPoint;
LatLng pt = LatLng(mp.coordinates[0][1], mp.coordinates[0][0]);
@ -578,8 +536,8 @@ class DestinationController extends GetxController {
double latFs = pt.latitude;
double lonFs = pt.longitude;
var distanceFs = const Distance();
double distFs = distanceFs.as(
LengthUnit.Meter, LatLng(latFs, lonFs), LatLng(la, ln));
double distFs = distanceFs.as(LengthUnit.Meter, LatLng(latFs, lonFs),
LatLng(currentLat, currentLon));
Destination des = festuretoDestination(fs);
if (distFs <= des.checkin_radious! && skipGps == false) {
@ -729,6 +687,7 @@ class DestinationController extends GetxController {
Future<void> startGame() async {
//print("------ starting game ------");
if (game_started == false) {
await checkForCheckin();
}
@ -736,10 +695,41 @@ class DestinationController extends GetxController {
@override
void onInit() async {
ever(locationController.currentPosition, handleLocationUpdate);
startGame();
super.onInit();
}
@override
void onClose() {
locationController.stopPositionStream();
}
void handleLocationUpdate(Position? position) async {
if (position != null) {
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}");
LogManager().addLog(
"GPS : $currentLat, $currentLon - ${DateTime.now().hour}:${DateTime.now().minute}:${DateTime.now().second}:${DateTime.now().microsecond}");
await addGPStoDB(position.latitude, position.longitude);
lastGPSCollectedTime = DateTime.now();
}
currentLat = position.latitude;
currentLon = position.longitude;
}
}
double distanceToStart() {
//print("=== gfs len == ${indexController.locations[0].collection.length}");
double distanceToDest = double.infinity;

View File

@ -42,7 +42,7 @@ class DestinationMapPage extends StatelessWidget {
//print("^^^^ $d ^^^^");
Marker m = Marker(
point: LatLng(d.lat!, d.lon!),
alignment: Alignment.topCenter,
alignment: Alignment.center,
child: InkWell(
onTap: () {
//print("-- Destination is --- ${d.name} ------");

View File

@ -126,7 +126,7 @@ class _GpsPageState extends State<GpsPage> {
MarkerLayer(
markers: gpsData.map((i) {
return Marker(
alignment: Alignment.topCenter,
alignment: Alignment.center,
height: 32.0,
width: 120.0,
point: LatLng(i.lat, i.lon),

View File

@ -1,11 +1,13 @@
import 'package:get/get.dart';
import 'package:rogapp/pages/destination/destination_controller.dart';
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/utils/location_controller.dart';
class IndexBinding extends Bindings {
@override
void dependencies() {
Get.put<IndexController>(IndexController());
Get.put<LocationController>(LocationController());
Get.put<DestinationController>(DestinationController());
}
}

View File

@ -1,16 +1,15 @@
import 'package:flutter/material.dart';
class LoadingPage extends StatelessWidget {
const LoadingPage({ Key? key }) : super(key: key);
const LoadingPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.topCenter,
margin: const EdgeInsets.only(top: 20),
child: const CircularProgressIndicator(
value: 0.8,
)
);
alignment: Alignment.center,
margin: const EdgeInsets.only(top: 20),
child: const CircularProgressIndicator(
value: 0.8,
));
}
}
}