update
This commit is contained in:
44
lib/services/maxtrix_service.dart
Normal file
44
lib/services/maxtrix_service.dart
Normal file
@ -0,0 +1,44 @@
|
||||
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
|
||||
class MatrixService{
|
||||
|
||||
static Future<Map<String, dynamic>> getDestinations(List<dynamic> destinations) async {
|
||||
|
||||
String locs = "";
|
||||
String origin = "";
|
||||
int i = 0;
|
||||
for(Map<String, dynamic> loc in destinations){
|
||||
|
||||
if(i==0){
|
||||
origin = "${loc["location"]["geometry"]["coordinates"][0][1]}, ${loc["location"]["geometry"]["coordinates"][0][0]}";
|
||||
}
|
||||
|
||||
print("lat is ${loc["location"]["geometry"]["coordinates"][0][1]}, long is ${loc["location"]["geometry"]["coordinates"][0][0]}");
|
||||
locs += "${loc["location"]["geometry"]["coordinates"][0][1]}, ${loc["location"]["geometry"]["coordinates"][0][0]}|";
|
||||
i++;
|
||||
}
|
||||
|
||||
//print(locs);
|
||||
|
||||
Map<String, dynamic> cats = {};
|
||||
String url = "https://maps.googleapis.com/maps/api/distancematrix/json?destinations=${locs}&origins=${origin}&key=AIzaSyBLgnwft3py6c4YkT-MxZ9y4zYGFgAEmRk";
|
||||
print(url);
|
||||
final http.Response response = await http.get(
|
||||
Uri.parse(url),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
}
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
return cats;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user