feat: (broken) implement route map and address autocomplete widgets with associated infrastructure testing scripts
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import '../lib/utils/polyline_utils.dart';
|
||||
|
||||
void main() async {
|
||||
final origin = "401 route du camping, 69850 Saint Martin en haut";
|
||||
final destination = "Salle des fêtes, Orliénas";
|
||||
|
||||
final requestBody = jsonEncode({
|
||||
"data": {
|
||||
"origin": origin,
|
||||
"destination": destination,
|
||||
"vehicleTollCategory": 2
|
||||
}
|
||||
});
|
||||
|
||||
print("Fetching route...");
|
||||
final request = await HttpClient().postUrl(Uri.parse('https://googlemapscomputeroute-iarazmuuzq-od.a.run.app'));
|
||||
request.headers.set('Content-Type', 'application/json');
|
||||
request.write(requestBody);
|
||||
|
||||
final response = await request.close();
|
||||
final responseBody = await response.transform(utf8.decoder).join();
|
||||
|
||||
print("Status: ${response.statusCode}");
|
||||
|
||||
try {
|
||||
final json = jsonDecode(responseBody);
|
||||
final routes = json['routes'] as List;
|
||||
for (int i = 0; i < routes.length; i++) {
|
||||
final polyStr = routes[i]['encodedPolyline'];
|
||||
print("Route $i polyline length: ${polyStr.length}");
|
||||
final pts = safeDecodePolyline(polyStr);
|
||||
print("Route $i points decoded: ${pts.length}");
|
||||
if (pts.isNotEmpty) {
|
||||
print(" Start: ${pts.first.latitude}, ${pts.first.longitude}");
|
||||
print(" End: ${pts.last.latitude}, ${pts.last.longitude}");
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print("Error parsing: $e");
|
||||
print(responseBody);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user