This commit is contained in:
Mohamed Nouffer
2022-05-24 20:43:41 +05:30
parent ee0440e6b6
commit 3cb7865d3b
60 changed files with 342 additions and 100 deletions

View File

@ -1,4 +1,7 @@
import 'dart:convert';
import 'dart:ffi';
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
//import 'package:google_maps_webservice/directions.dart';
import 'package:http/http.dart' as http;
@ -36,6 +39,35 @@ class DestinationService{
return cats;
}
static Future<List<PointLatLng>>? getDestinationLine(List<dynamic> destinations) async{
PolylinePoints polylinePoints = PolylinePoints();
//print("##### @@@@@ ${destinations[0]["location"]["geometry"]["coordinates"][0][1]}");
PointLatLng origin = PointLatLng(destinations[0]["location"]["geometry"]["coordinates"][0][1], destinations[0]["location"]["geometry"]["coordinates"][0][0]);
PointLatLng dest = PointLatLng(destinations[destinations.length -1]["location"]["geometry"]["coordinates"][0][1], destinations[destinations.length -1]["location"]["geometry"]["coordinates"][0][0]);
List<PolylineWayPoint> wayPoints = [];
int i=0;
for(dynamic d in destinations){
if(i == 0 || i == (destinations.length -1)){
i+=1;
continue;
}
double la = d["location"]["geometry"]["coordinates"][0][1]as double;
double ln = d["location"]["geometry"]["coordinates"][0][0] as double;
PolylineWayPoint pwp = PolylineWayPoint(location: "${la},${ln}", stopOver: true);
//print("----- UUUUUU ${pwp}");
//PointLatLng wp = PointLatLng(d["Location"]["geometry"][0][1], d["Location"]["geometry"][0][0]);
wayPoints.add(pwp);
i+=1;
}
//PolylineResult result = await polylinePoints.getRouteBetweenCoordinates("AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE", PointLatLng(35.389282, 136.498027), PointLatLng(36.285848, 137.575186));
PolylineResult result = await polylinePoints.getRouteBetweenCoordinates("AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE", origin,dest, travelMode: TravelMode.driving, wayPoints: wayPoints);
//print("#####@@@@@ ${result.points}");
return result.points;
}
}

View File

@ -24,7 +24,7 @@ class MatrixService{
//print(locs);
Map<String, dynamic> cats = {};
String url = "https://maps.googleapis.com/maps/api/distancematrix/json?destinations=${locs}&origins=${origin}&key=AIzaSyBLgnwft3py6c4YkT-MxZ9y4zYGFgAEmRk";
String url = "https://maps.googleapis.com/maps/api/distancematrix/json?destinations=${locs}&origins=${origin}&key=AIzaSyAUBI1ablMKuJwGj2-kSuEhvYxvB1A-mOE";
print(url);
final http.Response response = await http.get(
Uri.parse(url),