fetchDistanceMatrix method
Future<MFDistanceMatrixResult>
fetchDistanceMatrix(
- List<
MFLocationComponent> origins, - List<
MFLocationComponent> destinations, { - MFTravelMode mode = MFTravelMode.car,
- MFRouteWeighting weighting = MFRouteWeighting.fastest,
- MFLanguageResult language = MFLanguageResult.vi,
- 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'])!;
}