fixed distance Mx

This commit is contained in:
Mohamed Nouffer
2023-06-14 11:27:11 +05:30
parent 6c8ac75b19
commit 3e06c4cd7f
2 changed files with 113 additions and 116 deletions

View File

@ -20,7 +20,6 @@ class _ListWidgetState extends State<ListWidget> {
final IndexController indexController = Get.find<IndexController>();
final DestinationController destinationController = Get.find<DestinationController>();
List<Destination> destList = [];
Image getImage(int index){
if(indexController.locations[0].collection[index].properties!["photos"] == null || indexController.locations[0].collection[index].properties!["photos"] == ""){
@ -49,43 +48,41 @@ class _ListWidgetState extends State<ListWidget> {
indexController.currentFeature.add(fs);
}
void getDestinationCoords() {
Destination cdes = Destination(lat: indexController.current_lat, lon: indexController.current_lon);
List<Destination> dest = [cdes];
for(int k=0; k < indexController.locations[0].collection.length; k++){
GeoJsonMultiPoint _pt = indexController.locations[0].collection[k].geometry;
final de = Destination(
lat: _pt.geoSerie!.geoPoints.first.latitude,
lon: _pt.geoSerie!.geoPoints.first.longitude,
);
//print("---dest a is: ${dest} ---");
dest.insert(0, de);
}
destList.assignAll(dest);
//print("--- dest is: ${dest} ---");
}
@override
void initState() {
super.initState();
getDestinationCoords();
}
Destination createDestination(GeoJsonFeature feature) {
final props = feature.properties;
GeoJsonMultiPoint _pt = feature.geometry;
return Destination(
cp: props!['cp'],
lat: _pt.geoSerie!.geoPoints.first.latitude,
lon: _pt.geoSerie!.geoPoints.first.longitude,
);
}
Future<String> matrixDistance(int i) async {
final res = await MatrixService.getDestinations(destList.sublist(i, i+2));
// Create two destinations directly from indexController.locations[0].collection
Destination dest1 = createDestination(indexController.locations[0].collection[i]);
Destination dest2 = createDestination(indexController.locations[0].collection[i+1]);
// Get the distance between these two destinations
final res = await MatrixService.getDestinations([dest1, dest2]);
return res["routes"][0]["legs"][0]["distance"]["text"];
//print("matrix result is ${i} : ${res["routes"][0]["legs"][0]["distance"]["text"]} ");
}
Future<void> _pullRefresh() async {
print("pull to refesh");
setState(() {
indexController.locations[0].collection.sort((a, b) =>
indexController.locations[0].collection.sort((a, b) =>
(a.properties!['cp'] as Comparable)
.compareTo(b.properties!['cp'] as Comparable));
setState(() {
});
// why use freshNumbers var? https://stackoverflow.com/a/52992836/2301224
}
@override