parseRoad function
parseRoad
this method used to parse json get it from route service to Road
object
we use this method in another thread like compute
the data
is ParserRoadComputeArg
that will to be parsed to Road
fix parsing problem #1
return Road
object that contain list of waypoint
and distance and duration of the road
Implementation
Future<OSRMRoad> parseRoad(ParserRoadComputeArg data) async {
Map<String, dynamic> jsonResponse = data.json;
bool alternative = data.alternative;
var road = const OSRMRoad.empty();
final List<Map<String, dynamic>> routes =
List.castFrom(jsonResponse["routes"]);
final route = routes.first;
road = OSRMRoad.fromOSRMJson(
route: route,
);
if (routes.length > 1 && alternative) {
routes.removeAt(0);
for (var route in routes) {
final alternative = OSRMRoad.fromOSRMJson(
route: route,
);
road.addAlternativeRoute(alternative);
}
}
return road;
}