fetchDirections method

Future<MFDirectionsResult> fetchDirections(
  1. MFLocationComponent origin,
  2. MFLocationComponent destination, {
  3. List<MFLocationComponent>? waypoints,
  4. MFTravelMode mode = MFTravelMode.car,
  5. MFRouteWeighting weighting = MFRouteWeighting.fastest,
  6. MFLanguageResult language = MFLanguageResult.vi,
  7. MFRouteRestriction? restriction,
})

Get router.

Implementation

Future<MFDirectionsResult> fetchDirections(
  MFLocationComponent origin,
  MFLocationComponent destination, {
  List<MFLocationComponent>? waypoints,
  MFTravelMode mode = MFTravelMode.car,
  MFRouteWeighting weighting = MFRouteWeighting.fastest,
  MFLanguageResult language = MFLanguageResult.vi,
  MFRouteRestriction? restriction,
}) async {
  final Map<String, Object> data = <String, Object>{
    'origin': origin.toJson(),
    'destination': destination.toJson(),
    'mode': mode.index,
    'weighting': weighting.index,
    'language': language.index,
  };

  if (waypoints != null) {
    data['points'] = locationsToJson(waypoints);
  }
  if (restriction != null) {
    data['restriction'] = restriction.toJson();
  }

  final response = await _ServicesChannel.invokeService('route#route', data);
  validateResponse(response);

  return DirectionsResult.fromMap(response!['result'])!;
}