fixed gps page

This commit is contained in:
2023-11-22 23:06:38 +05:30
parent 4e4cfda40b
commit 23fde37e3d
6 changed files with 114 additions and 47 deletions

View File

@ -499,6 +499,22 @@ class DestinationController extends GetxController {
}
}
Future<void> addGPStoDB(double la, double ln, {isCheckin = 0}) async {
GpsDatabaseHelper db = GpsDatabaseHelper.instance;
final team_name = indexController.currentUser[0]["user"]['team_name'];
final event_code = indexController.currentUser[0]["user"]["event_code"];
GpsData gps_data = GpsData(
id: 0,
team_name: team_name,
event_code: event_code,
lat: la,
lon: ln,
is_checkin: isCheckin,
created_at: DateTime.now().microsecondsSinceEpoch);
var res = await db.insertGps(gps_data);
print("==gps res == ${res}");
}
Future<void> checkForCheckin() async {
print("--- Start of checkForCheckin function ---");
@ -512,21 +528,22 @@ class DestinationController extends GetxController {
final la = position.latitude;
final ln = position.longitude;
print("--- gps is ${la}, ${ln}");
//print("--- gps is ${la}, ${ln}");
//add gps to database
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);
await addGPStoDB(la, ln);
// 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);
for (GeoJsonFeature fs in indexController.locations[0].collection) {
GeoJsonMultiPoint mp = fs.geometry as GeoJsonMultiPoint;
@ -648,6 +665,8 @@ class DestinationController extends GetxController {
DateTime now = DateTime.now();
String formattedDate = DateFormat('yyyy-MM-dd HH:mm:ss').format(now);
await addGPStoDB(destination.lat!, destination.lon!, isCheckin: 1);
// print("------ checkin event $eventCode ------");
ExternalService()
.makeCheckpoint(userId, token, formattedDate, team, cpNum.round(),
@ -658,6 +677,10 @@ class DestinationController extends GetxController {
}
}
Future<void> removeCheckin(int cp) {
return ExternalService().removeCheckin(cp);
}
Future<void> startGame() async {
//print("------ starting game ------");
await checkForCheckin();

View File

@ -35,8 +35,10 @@ class _GpsPageState extends State<GpsPage> {
final team_name = indexController.currentUser[0]["user"]['team_name'];
final event_code = indexController.currentUser[0]["user"]["event_code"];
GpsDatabaseHelper db = GpsDatabaseHelper.instance;
gpsData.value = await db.getGPSData(team_name, event_code);
print("--- gps data ${gpsData.value[gpsData.length - 1].lat} ----");
var data = await db.getGPSData(team_name, event_code);
gpsData.value = data;
print("--- gps data ${data} ----");
}
Widget getMarkerShape(GpsData i) {
@ -50,10 +52,11 @@ class _GpsPageState extends State<GpsPage> {
width: 22,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.purple.shade300,
color: Colors.transparent,
border: Border.all(
color: Colors.purple,
width: 3,
color:
i.is_checkin == 0 ? Colors.blueAccent : Colors.green,
width: i.is_checkin == 0 ? 0.4 : 2,
style: BorderStyle.solid)),
child: const Stack(
alignment: Alignment.center,
@ -66,24 +69,26 @@ class _GpsPageState extends State<GpsPage> {
)),
),
Container(
color: Colors.white,
child: Text(
DateTime.fromMicrosecondsSinceEpoch(i.created_at)
.hour
.toString() +
":" +
color: Colors.transparent,
child: i.is_checkin == 1
? Text(
DateTime.fromMicrosecondsSinceEpoch(i.created_at)
.minute
.toString(),
// ":" +
// DateTime.fromMicrosecondsSinceEpoch(i.created_at)
// .second
// .toString(),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.black,
))),
.hour
.toString() +
":" +
DateTime.fromMicrosecondsSinceEpoch(i.created_at)
.minute
.toString(),
// ":" +
// DateTime.fromMicrosecondsSinceEpoch(i.created_at)
// .second
// .toString(),
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.black,
))
: Container()),
],
);
}
@ -100,16 +105,7 @@ class _GpsPageState extends State<GpsPage> {
mapController: mapController,
options: MapOptions(
maxZoom: 18.4,
onMapReady: () {
subscription =
mapController!.mapEventStream.listen((MapEvent mapEvent) {
if (mapEvent is MapEventMoveStart) {
//print(DateTime.now().toString() + ' [MapEventMoveStart] START');
// do something
}
if (mapEvent is MapEventMoveEnd) {}
});
},
onMapReady: () {},
//center: LatLng(37.15319600454702, 139.58765950528198),
bounds: indexController.currentBound.isNotEmpty
? indexController.currentBound[0]