getRoad method

Future<Road> getRoad({
  1. required List<LngLat> waypoints,
  2. RoadType roadType = RoadType.car,
  3. bool alternative = false,
  4. bool steps = true,
  5. Overview overview = Overview.full,
  6. Geometries geometries = Geometries.geojson,
  7. Languages language = Languages.en,
})

getRoad

this method make http call to get road from specific server this method return Road that contain road information like distance and duration and instruction or return Road with empty values.

return Road object that contain information of road that will help to draw road in the map or show important information to the user you should take a specific case when road object will contain empty values like 0.0 or empty string in case of any problem

Implementation

Future<Road> getRoad({
  required List<LngLat> waypoints,
  RoadType roadType = RoadType.car,
  bool alternative = false,
  bool steps = true,
  Overview overview = Overview.full,
  Geometries geometries = Geometries.geojson,
  Languages language = Languages.en,
}) async {
  String path = generatePath(
    server,
    waypoints.toWaypoints(),
    steps: steps,
    overview: overview,
    geometries: geometries,
    roadType: roadType,
  );
  path += "&alternatives=$alternative";
  final response = await dio.get(path);
  if (response.statusCode == 200) {
    final Map<String, dynamic> responseJson = response.data;
    return compute(
      parseRoad,
      ParserRoadComputeArg(
        jsonRoad: responseJson,
        langCode: language.name,
        alternative: alternative,
      ),
    );
  } else {
    return Road.withError();
  }
}