fetchDistanceMatrix method

Future<MFDistanceMatrixResult> fetchDistanceMatrix(
  1. List<MFLocationComponent> origins,
  2. List<MFLocationComponent> destinations, {
  3. MFTravelMode mode = MFTravelMode.car,
  4. MFRouteWeighting weighting = MFRouteWeighting.fastest,
  5. MFLanguageResult language = MFLanguageResult.vi,
  6. MFRouteRestriction? restriction,
})

The Distance Matrix API is a service that provides travel distance and time for a matrix of origins and destinations.

Implementation

Future<MFDistanceMatrixResult> fetchDistanceMatrix(
  List<MFLocationComponent> origins,
  List<MFLocationComponent> destinations, {
  MFTravelMode mode = MFTravelMode.car,
  MFRouteWeighting weighting = MFRouteWeighting.fastest,
  MFLanguageResult language = MFLanguageResult.vi,
  MFRouteRestriction? restriction,
}) async {
  final Map<String, Object> data = <String, Object>{
    'origins': locationsToJson(origins),
    'destinations': locationsToJson(destinations),
    'mode': mode.index,
    'weighting': weighting.index,
    'language': language.index,
  };

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

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

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