update
This commit is contained in:
@ -1,15 +1,22 @@
|
||||
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geojson/geojson.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:rogapp/pages/index/index_controller.dart';
|
||||
import 'package:rogapp/routes/app_pages.dart';
|
||||
import 'package:rogapp/services/destination_service.dart';
|
||||
import 'package:rogapp/services/maxtrix_service.dart';
|
||||
import 'package:rogapp/services/reacking_service.dart';
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:rogapp/widgets/bottom_sheet_widget.dart';
|
||||
|
||||
class DestinationController extends GetxController {
|
||||
|
||||
late LocationSettings locationSettings;
|
||||
@ -17,21 +24,91 @@ class DestinationController extends GetxController {
|
||||
List<dynamic> destinations = <dynamic>[].obs;
|
||||
List<Map<String, dynamic>> destination_index_data = <Map<String, dynamic>>[].obs;
|
||||
|
||||
bool checking_in = false;
|
||||
List<bool> isSelected = [true].obs;
|
||||
BuildContext? context;
|
||||
|
||||
Map<String, dynamic> matrix = {};
|
||||
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
|
||||
|
||||
Future<GeoJsonFeature?> getDEstinationForLatLong(double lat, double long)async {
|
||||
|
||||
String jjjj = '{"id":1,"type":"Feature","geometry":{"type":"MultiPoint","coordinates":[[136.731357,35.370094]]},"properties":{"location_id":915101,"location_name":"柳津","category":"買い物","zip":"〒501-6100","address":"柳津町字仙右城7696-1"}}';
|
||||
|
||||
for(final d in destinations){
|
||||
var geom = d["location"]["geometry"];
|
||||
var props = d["location"]["properties"];
|
||||
print("--props- ${d["location"]["geometry"]["coordinates"][0][1]}");
|
||||
List<dynamic> geom_multi = [geom];
|
||||
Map<String, dynamic> final_geom = {"features":[{"id":d["id"],"type":"Feature", "geometry": geom, "properties": props}]};
|
||||
//print("----- geom : ${final_geom}");
|
||||
|
||||
String js = json.encode(final_geom);
|
||||
//print("---features-- ${js}-----");
|
||||
GeoJsonFeatureCollection features = await featuresFromGeoJson(js);
|
||||
GeoJsonMultiPoint p = features.collection[0].geometry as GeoJsonMultiPoint;
|
||||
if(lat == p.geoSerie!.geoPoints[0].latitude && long == p.geoSerie!.geoPoints[0].longitude){
|
||||
return features.collection[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkForCheckin(double la, double ln){
|
||||
for(final d in destinations){
|
||||
double lat = d["location"]["geometry"]["coordinates"][0][1] as double;
|
||||
double lon = d["location"]["geometry"]["coordinates"][0][0] as double;
|
||||
LatLng p = LatLng(lat, lon);
|
||||
getDEstinationForLatLong(lat, lon).then((value){
|
||||
var distance = Distance();
|
||||
double dist = distance.as(LengthUnit.Meter, LatLng(lat, lon), LatLng(la, ln));
|
||||
double rad = value!.properties!["checkin_radious"] ?? double.infinity;
|
||||
bool auto_checkin = value.properties!["auto_checkin"] ?? false;
|
||||
|
||||
indexController.currentFeature.add(value);
|
||||
indexController.getAction();
|
||||
|
||||
if(!checking_in){
|
||||
checking_in = true;
|
||||
if(rad >= dist){
|
||||
if(auto_checkin){
|
||||
if(indexController.currentAction.isNotEmpty){
|
||||
print(indexController.currentAction[0]);
|
||||
indexController.currentAction[0][0]["checkin"] = true;
|
||||
Map<String,dynamic> temp = Map<String,dynamic>.from(indexController.currentAction[0][0]);
|
||||
indexController.currentAction.clear();
|
||||
print("---temp---${temp}");
|
||||
indexController.currentAction.add([temp]);
|
||||
}
|
||||
indexController.makeAction(Get.context!);
|
||||
}
|
||||
else{
|
||||
showModalBottomSheet(context: Get.context!, isScrollControlled: true,
|
||||
builder:((context) => BottomSheetWidget())
|
||||
).whenComplete((){
|
||||
checking_in = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
print("----- rad is ${rad}");
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
PopulateDestinations();
|
||||
|
||||
|
||||
|
||||
|
||||
if (defaultTargetPlatform == TargetPlatform.android) {
|
||||
locationSettings = AndroidSettings(
|
||||
accuracy: LocationAccuracy.high,
|
||||
distanceFilter: 1,
|
||||
distanceFilter: 30,
|
||||
forceLocationManager: true,
|
||||
intervalDuration: const Duration(seconds: 10),
|
||||
//(Optional) Set foreground notification config to keep the app alive
|
||||
@ -55,13 +132,20 @@ class DestinationController extends GetxController {
|
||||
} else {
|
||||
locationSettings = LocationSettings(
|
||||
accuracy: LocationAccuracy.high,
|
||||
distanceFilter: 1,
|
||||
distanceFilter: 30,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
StreamSubscription<Position> positionStream = Geolocator.getPositionStream(locationSettings: locationSettings).listen(
|
||||
(Position? position) {
|
||||
if(isSelected[0]){
|
||||
String user_id = indexController.currentUser[0]["user"]["id"].toString();
|
||||
TrackingService.addTrack(user_id, position!.latitude, position.longitude).then((val){
|
||||
//checkForCheckin(position!.latitude, position.longitude);
|
||||
});
|
||||
|
||||
}
|
||||
print(position == null ? 'Unknown' : 'current position is ${position.latitude.toString()}, ${position.longitude.toString()}');
|
||||
});
|
||||
|
||||
@ -80,7 +164,7 @@ class DestinationController extends GetxController {
|
||||
|
||||
void PopulateDestinations(){
|
||||
if(indexController.currentUser.isNotEmpty){
|
||||
int user_id = indexController.currentUser[0]["user"]["id"] as int;
|
||||
int user_id = indexController.currentUser[0]["user"]["id"];
|
||||
//print(user_id);
|
||||
DestinationService.getDestinations(user_id).then((value){
|
||||
|
||||
|
||||
Reference in New Issue
Block a user