update for flutter_map
This commit is contained in:
@ -1,47 +1,47 @@
|
||||
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:rogapp/model/destination.dart';
|
||||
// import 'dart:convert';
|
||||
// import 'package:http/http.dart' as http;
|
||||
// import 'package:rogapp/model/destination.dart';
|
||||
|
||||
|
||||
class MatrixService{
|
||||
// class MatrixService{
|
||||
|
||||
static Future<Map<String, dynamic>> getDestinations(List<Destination> destinations) async {
|
||||
// static Future<Map<String, dynamic>> getDestinations(List<Destination> destinations) async {
|
||||
|
||||
String locs = "";
|
||||
String origin = "";
|
||||
int i = 0;
|
||||
for(Destination d in destinations){
|
||||
// String locs = "";
|
||||
// String origin = "";
|
||||
// int i = 0;
|
||||
// for(Destination d in destinations){
|
||||
|
||||
print("---- getting matrix for ${d} ------------");
|
||||
// print("---- getting matrix for ${d} ------------");
|
||||
|
||||
if(i==0){
|
||||
origin = "${d.lat}, ${d.lon}";
|
||||
}
|
||||
// if(i==0){
|
||||
// origin = "${d.lat}, ${d.lon}";
|
||||
// }
|
||||
|
||||
print("lat is ${d.lat}, long is ${d.lon}");
|
||||
locs += "${d.lat}, ${d.lon}|";
|
||||
i++;
|
||||
}
|
||||
// print("lat is ${d.lat}, long is ${d.lon}");
|
||||
// locs += "${d.lat}, ${d.lon}|";
|
||||
// i++;
|
||||
// }
|
||||
|
||||
//print(locs);
|
||||
// //print(locs);
|
||||
|
||||
Map<String, dynamic> cats = {};
|
||||
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),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
}
|
||||
);
|
||||
// Map<String, dynamic> cats = {};
|
||||
// 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),
|
||||
// headers: <String, String>{
|
||||
// 'Content-Type': 'application/json; charset=UTF-8',
|
||||
// }
|
||||
// );
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
}
|
||||
return cats;
|
||||
}
|
||||
// if (response.statusCode == 200) {
|
||||
// cats = json.decode(utf8.decode(response.bodyBytes));
|
||||
// }
|
||||
// return cats;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user