map updated to 6
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'package:camera_camera/camera_camera.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:geojson/geojson.dart';
|
||||
import 'package:geojson_vi/geojson_vi.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
@ -26,7 +27,8 @@ import 'dart:async';
|
||||
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
|
||||
import 'package:rogapp/widgets/debug_widget.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:gallery_saver/gallery_saver.dart';
|
||||
|
||||
import 'package:image_gallery_saver/image_gallery_saver.dart';
|
||||
|
||||
class DestinationController extends GetxController {
|
||||
late LocationSettings locationSettings;
|
||||
@ -79,10 +81,9 @@ class DestinationController extends GetxController {
|
||||
return DateFormat('yyyy-MM-dd HH:mm:ss').format(datetime);
|
||||
}
|
||||
|
||||
Destination festuretoDestination(GeoJsonFeature fs) {
|
||||
GeoJsonMultiPoint mp = fs.geometry as GeoJsonMultiPoint;
|
||||
LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude,
|
||||
mp.geoSerie!.geoPoints[0].longitude);
|
||||
Destination festuretoDestination(GeoJSONFeature fs) {
|
||||
GeoJSONMultiPoint mp = fs.geometry as GeoJSONMultiPoint;
|
||||
LatLng pt = LatLng(mp.coordinates[0][1], mp.coordinates[0][0]);
|
||||
|
||||
//print("----- ${indexController.currentFeature[0].properties} -----");
|
||||
|
||||
@ -112,7 +113,7 @@ class DestinationController extends GetxController {
|
||||
tags: fs.properties!["tags"]);
|
||||
}
|
||||
|
||||
Future<void> startTimerLocation(GeoJsonFeature fs, double distance) async {
|
||||
Future<void> startTimerLocation(GeoJSONFeature fs, double distance) async {
|
||||
//print("---- in startTimer ----");
|
||||
// print("---- is in rog is $is_in_rog ----");
|
||||
double checkinRadious = fs.properties!['checkin_radius'] ?? double.infinity;
|
||||
@ -570,32 +571,23 @@ class DestinationController extends GetxController {
|
||||
// created_at: DateTime.now().microsecondsSinceEpoch);
|
||||
// await db.insertGps(gps_data);
|
||||
|
||||
for (GeoJsonFeature fs in indexController.locations[0].collection) {
|
||||
GeoJsonMultiPoint mp = fs.geometry as GeoJsonMultiPoint;
|
||||
LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude,
|
||||
mp.geoSerie!.geoPoints[0].longitude);
|
||||
indexController.locations[0].features.forEach((fs) async {
|
||||
GeoJSONMultiPoint mp = fs!.geometry as GeoJSONMultiPoint;
|
||||
LatLng pt = LatLng(mp.coordinates[0][1], mp.coordinates[0][0]);
|
||||
|
||||
double latFs = pt.latitude;
|
||||
double lonFs = pt.longitude;
|
||||
var distanceFs = const Distance();
|
||||
//print("--- points : ${pt.latitude}, ${pt.longitude} ----");
|
||||
//print("--- points : ${pt.latitude}, ${pt.longitude} ----");
|
||||
double distFs = distanceFs.as(
|
||||
LengthUnit.Meter, LatLng(latFs, lonFs), LatLng(la, ln));
|
||||
Destination des = festuretoDestination(fs);
|
||||
|
||||
//print(
|
||||
// "--- position is ---- ${position.longitude}, --- ${position.longitude}----");
|
||||
|
||||
//print("--- distFs ---- $distFs, --- ${des.checkin_radious}----");
|
||||
if (distFs <= des.checkin_radious! && skipGps == false) {
|
||||
//print("--- 789 ---- $skip_gps----");
|
||||
//near a location
|
||||
//print("---- before call startTimerLocation ----");
|
||||
await startTimerLocation(fs, distFs);
|
||||
break;
|
||||
// Note: You cannot break out of forEach. If you need to stop processing, you might have to reconsider using forEach.
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (gps_push_started == false) {
|
||||
pushGPStoServer();
|
||||
}
|
||||
@ -644,11 +636,21 @@ class DestinationController extends GetxController {
|
||||
populateDestinations();
|
||||
}
|
||||
|
||||
_saveImageFromPath(String imagePath) async {
|
||||
// Read the image file from the given path
|
||||
File imageFile = File(imagePath);
|
||||
Uint8List imageBytes = await imageFile.readAsBytes();
|
||||
|
||||
// Save the image to the gallery
|
||||
final result = await ImageGallerySaver.saveImage(imageBytes);
|
||||
print(result);
|
||||
}
|
||||
|
||||
Future<void> makeBuyPoint(Destination destination, String imageurl) async {
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
await db.updateBuyPoint(destination, imageurl);
|
||||
populateDestinations();
|
||||
await GallerySaver.saveImage(imageurl);
|
||||
await _saveImageFromPath(imageurl);
|
||||
|
||||
if (indexController.currentUser.isNotEmpty) {
|
||||
double cpNum = destination.cp!;
|
||||
@ -690,7 +692,7 @@ class DestinationController extends GetxController {
|
||||
// print("~~~~ inserted into db ~~~~");
|
||||
}
|
||||
|
||||
await GallerySaver.saveImage(imageurl);
|
||||
await _saveImageFromPath(imageurl);
|
||||
|
||||
populateDestinations();
|
||||
|
||||
@ -740,14 +742,23 @@ class DestinationController extends GetxController {
|
||||
|
||||
double distanceToStart() {
|
||||
//print("=== gfs len == ${indexController.locations[0].collection.length}");
|
||||
GeoJsonFeature gfs = indexController.locations[0].collection
|
||||
.firstWhere((element) => festuretoDestination(element).cp == -1);
|
||||
double distanceToDest = double.infinity;
|
||||
if (indexController.locations[0].features.isEmpty) {
|
||||
return distanceToDest;
|
||||
}
|
||||
GeoJSONFeature? gfs = indexController.locations[0].features.firstWhere(
|
||||
(element) => festuretoDestination(element!).cp == -1,
|
||||
orElse: () => null, // Provide a null value if no element is found
|
||||
);
|
||||
|
||||
if (gfs == null) {
|
||||
return distanceToDest;
|
||||
}
|
||||
|
||||
Destination des = festuretoDestination(gfs);
|
||||
|
||||
//print("=== gfs == ${des.toMap()}");
|
||||
|
||||
double distanceToDest = double.infinity;
|
||||
var distance = const Distance();
|
||||
distanceToDest = distance.as(LengthUnit.Meter,
|
||||
LatLng(currentLat, currentLon), LatLng(des.lat!, des.lon!));
|
||||
@ -761,8 +772,14 @@ class DestinationController extends GetxController {
|
||||
return 500;
|
||||
}
|
||||
Destination? ds;
|
||||
GeoJsonFeature gfs = indexController.locations[0].collection
|
||||
.firstWhere((element) => festuretoDestination(element).cp == -1);
|
||||
GeoJSONFeature? gfs = indexController.locations[0].features.firstWhere(
|
||||
(element) => festuretoDestination(element!).cp == -1,
|
||||
orElse: () => null, // Provide a null value if no element is found
|
||||
);
|
||||
|
||||
if (gfs == null) {
|
||||
return _retValue;
|
||||
}
|
||||
|
||||
ds = festuretoDestination(gfs);
|
||||
var distance = const Distance();
|
||||
|
||||
Reference in New Issue
Block a user