getMultiRouteDirectionsData method

Future<List<DirectionRouteData>> getMultiRouteDirectionsData({
  1. required List<Coordinate> coordinates,
  2. Object? alternativeRoutes,
  3. List<String>? attributes,
  4. bool continueStraight = false,
  5. bool? elevation,
  6. List<String>? extraInfo,
  7. bool geometrySimplify = false,
  8. String? id,
  9. bool instructions = true,
  10. String instructionsFormat = 'text',
  11. String language = 'en',
  12. bool maneuvers = false,
  13. Object? options,
  14. String preference = 'recommended',
  15. List<int>? radiuses,
  16. bool roundaboutExits = false,
  17. List<int>? skipSegments,
  18. bool suppressWarnings = false,
  19. String units = 'm',
  20. bool geometry = true,
  21. int? maximumSpeed,
  22. ORSProfile? profileOverride,
})

Fetches the Direction Route information for the route connecting the various coordinates from the openrouteservice API, and returns the entire geojson DirectionRouteData containing the response data.

To get the geojson GeoJsonFeatureCollection containing the response data, use ORSDirections.getMultiRouteDirectionsGeoJson.

To get only the parsed route coordinates, use ORSDirections.getMultiRouteCoordinates.

Information about the endpoint, parameters, response etc. can be found at: https://openrouteservice.org/dev/#/api-docs/v2/directions/{profile}/post

Implementation

Future<List<DirectionRouteData>> getMultiRouteDirectionsData({
  required List<Coordinate> coordinates,
  Object? alternativeRoutes,
  List<String>? attributes,
  bool continueStraight = false,
  bool? elevation,
  List<String>? extraInfo,
  bool geometrySimplify = false,
  String? id,
  bool instructions = true,
  String instructionsFormat = 'text',
  String language = 'en',
  bool maneuvers = false,
  Object? options,
  String preference = 'recommended',
  List<int>? radiuses,
  bool roundaboutExits = false,
  List<int>? skipSegments,
  bool suppressWarnings = false,
  String units = 'm',
  bool geometry = true,
  int? maximumSpeed,
  ORSProfile? profileOverride,
}) async {
  // If a path parameter override is provided, use it.
  final ORSProfile chosenPathParam = profileOverride ?? _profile;

  // Build the request URL.
  final Uri uri = Uri.parse(
    '$_directionsEndpointURL/${OpenRouteService.getProfileString(chosenPathParam)}',
  );

  // Ready data to be sent.
  final Map<String, dynamic> queryParameters = <String, dynamic>{
    'coordinates': coordinates
        .map<List<double>>(
          (Coordinate coordinate) =>
              <double>[coordinate.longitude, coordinate.latitude],
        )
        .toList(),
    'alternative_routes': alternativeRoutes,
    'attributes': attributes,
    'continue_straight': continueStraight,
    'elevation': elevation,
    'extra_info': extraInfo,
    'geometry_simplify': geometrySimplify,
    'id': id,
    'instructions': instructions,
    'instructions_format': instructionsFormat,
    'language': language,
    'maneuvers': maneuvers,
    'options': options,
    'preference': preference,
    'radiuses': radiuses,
    'roundabout_exits': roundaboutExits,
    'skip_segments': skipSegments,
    'suppress_warnings': suppressWarnings,
    'units': units,
    'geometry': geometry,
    'maximum_speed': maximumSpeed,
  }..removeWhere((key, value) => value == null);

  // Fetch the data.
  final Map<String, dynamic> data =
      await _openRouteServicePost(uri: uri, data: queryParameters);
  return (data['routes'] as List<dynamic>)
      .map<DirectionRouteData>(
        (dynamic route) => DirectionRouteData.fromJson(route),
      )
      .toList();
}