fetchDirections static method

Future<DrivingDirections> fetchDirections(
  1. String apiKey,
  2. String coordinates, {
  3. bool alternatives = false,
  4. bool steps = false,
  5. String geometries = 'polyline',
  6. String overview = 'full',
  7. bool annotations = false,
})

Implementation

static Future<DrivingDirections> fetchDirections(
    String apiKey, String coordinates,
    {bool alternatives = false,
    bool steps = false,
    String geometries = 'polyline',
    String overview = 'full',
    bool annotations = false}) async {
  final String apiUrl =
      'https://us1.locationiq.com/v1/directions/driving/$coordinates';
  final String url =
      '$apiUrl?key=$apiKey&alternatives=$alternatives&steps=$steps&geometries=$geometries&overview=$overview&annotations=$annotations';

  final response = await http.get(Uri.parse(url));

  if (response.statusCode == 200) {
    final Map<String, dynamic> data = json.decode(response.body);
    return DrivingDirections.fromJson(data);
  } else {
    throw Exception('Impossible de récupérer les directions');
  }
}