feat: (broken) implement route map and address autocomplete widgets with associated infrastructure testing scripts
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
void main() async {
|
||||
final envFile = File('functions/.env');
|
||||
final lines = await envFile.readAsLines();
|
||||
String apiKey = '';
|
||||
for (var line in lines) {
|
||||
if (line.startsWith('API_MAPS=')) {
|
||||
apiKey = line.split('=')[1].replaceAll('"', '');
|
||||
}
|
||||
}
|
||||
|
||||
final url = 'https://routes.googleapis.com/directions/v2:computeRoutes';
|
||||
final client = HttpClient();
|
||||
|
||||
final request = await client.postUrl(Uri.parse(url));
|
||||
request.headers.set('Content-Type', 'application/json');
|
||||
request.headers.set('X-Goog-Api-Key', apiKey);
|
||||
request.headers.set('X-Goog-FieldMask', 'routes.distanceMeters,routes.duration,routes.polyline.encodedPolyline');
|
||||
|
||||
final payload = jsonEncode({
|
||||
"travelMode": "DRIVE",
|
||||
"routingPreference": "TRAFFIC_AWARE",
|
||||
"origin": { "address": "401 route du camping, 69850 Saint Martin en haut" },
|
||||
"destination": { "address": "652431, 6853241" }
|
||||
});
|
||||
|
||||
request.write(payload);
|
||||
final response = await request.close();
|
||||
final responseBody = await response.transform(utf8.decoder).join();
|
||||
|
||||
print(responseBody);
|
||||
}
|
||||
Reference in New Issue
Block a user