buildUrl method
String
buildUrl({
- required List<
Object> origin, - required List<
Object> destination, - TravelMode? travelMode,
- String? languageCode,
- bool alternative = false,
- String? region,
- List<
RouteType> avoids = const <RouteType>[], - Unit? unit,
- Object? arrivalTime,
- Object? departureTime,
- List<
TransitMode> transitMode = const [], - TrafficModel? trafficModel,
- TransitRoutingPreferences? transitRoutingPreference,
Implementation
String buildUrl({
required List<Object /*Location|String*/ > origin,
required List<Object /*Location|String*/ > destination,
TravelMode? travelMode,
String? languageCode,
bool alternative = false,
String? region,
List<RouteType> avoids = const <RouteType>[],
Unit? unit,
Object? /*DateTime|num*/ arrivalTime,
Object? /*DateTime|num|String('now')*/ departureTime,
List<TransitMode> transitMode = const [],
TrafficModel? trafficModel,
TransitRoutingPreferences? transitRoutingPreference,
}) {
final params = <String, String>{};
if (origin is! List<Location> && origin is! List<String>) {
throw ArgumentError("'origin' must be a '$String' or a '$Location'");
}
params['origins'] = origin.join('|');
if (destination is! List<Location> && destination is! List<String>) {
throw ArgumentError("'destination' must be a '$String' or a '$Location'");
}
params['destinations'] = destination.join('|');
if (destination is! List<Location> && destination is! List<String>) {
throw ArgumentError("'destination' must be a '$String' or a '$Location'");
}
if (departureTime != null &&
departureTime is! DateTime &&
departureTime is! num &&
departureTime != 'now') {
throw ArgumentError("'departureTime' must be a '$num' or a '$DateTime'");
}
if (arrivalTime != null &&
arrivalTime is! DateTime &&
arrivalTime is! num) {
throw ArgumentError("'arrivalTime' must be a '$num' or a '$DateTime'");
}
if (departureTime != null) {
if (departureTime is! DateTime &&
departureTime is! num &&
departureTime != 'now') {
throw ArgumentError(
"'departureTime' must be a '$num' or a '$DateTime'");
}
params['departure_time'] = departureTime is DateTime
? (departureTime.millisecondsSinceEpoch ~/ 1000).toString()
: departureTime.toString();
}
if (arrivalTime != null) {
if (arrivalTime is! DateTime && arrivalTime is! num) {
throw ArgumentError("'arrivalTime' must be a '$num' or a '$DateTime'");
}
params['arrival_time'] = arrivalTime is DateTime
? (arrivalTime.millisecondsSinceEpoch ~/ 1000).toString()
: arrivalTime.toString();
}
if (travelMode != null) {
params['mode'] = travelMode.name;
}
if (alternative) {
params['alternative'] = alternative.toString();
}
if (avoids.isNotEmpty) {
params['avoid'] = avoids.map((t) => t.name).join('|');
}
if (languageCode != null) {
params['language'] = languageCode;
}
if (unit != null) {
params['units'] = unit.name;
}
if (region != null) {
params['region'] = region;
}
if (trafficModel != null) {
params['traffic_model'] = trafficModel.name;
}
if (transitMode.isNotEmpty) {
params['transit_mode'] = transitMode.map((t) => t.name).join('|');
}
if (transitRoutingPreference != null) {
params['transit_routing_preference'] = transitRoutingPreference.name;
}
if (apiKey != null) {
params['key'] = apiKey!;
}
return url.replace(queryParameters: params).toString();
}