buildUrl method
String
buildUrl({
- required Object origin,
- required Object destination,
- TravelMode? travelMode,
- List<
Waypoint> waypoints = const <Waypoint>[], - bool alternatives = false,
- List<
RouteType> avoids = const <RouteType>[], - String? language,
- Unit? units,
- String? region,
- Object? arrivalTime,
- Object? departureTime,
- List<
TransitMode> transitMode = const <TransitMode>[], - TrafficModel? trafficModel,
- TransitRoutingPreferences? transitRoutingPreference,
Implementation
String buildUrl({
required Object /*Location|String*/ origin,
required Object /*Location|String*/ destination,
TravelMode? travelMode,
List<Waypoint> waypoints = const <Waypoint>[],
bool alternatives = false,
List<RouteType> avoids = const <RouteType>[],
String? language,
Unit? units,
String? region,
Object? /*DateTime|num*/ arrivalTime,
Object? /*DateTime|num|String('now')*/ departureTime,
List<TransitMode> transitMode = const <TransitMode>[],
TrafficModel? trafficModel,
TransitRoutingPreferences? transitRoutingPreference,
}) {
final params = <String, String>{};
if (origin is! Location && origin is! String) {
throw ArgumentError("'origin' must be a '$String' or a '$Location'");
}
params['origin'] = origin.toString();
if (destination is! Location && destination is! String) {
throw ArgumentError("'destination' must be a '$String' or a '$Location'");
}
params['destination'] = destination.toString();
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 (waypoints.isNotEmpty == true) {
if (alternatives == true) {
throw ArgumentError(
"'alternatives' is only available for requests without intermediate waypoints",
);
}
params['waypoints'] = waypoints.join('|');
}
if (travelMode != null) {
params['mode'] = travelMode.toApiString();
}
if (alternatives) {
params['alternatives'] = alternatives.toString();
}
if (avoids.isNotEmpty) {
params['avoid'] = avoids.map((t) => t.toApiString()).join('|');
}
if (language != null) {
params['language'] = language;
}
if (units != null) {
params['units'] = units.toApiString();
}
if (region != null) {
params['region'] = region;
}
if (trafficModel != null) {
params['traffic_model'] = trafficModel.toApiString();
}
if (transitMode.isNotEmpty) {
params['transit_mode'] =
transitMode.map((t) => t.toApiString()).join('|');
}
if (transitRoutingPreference != null) {
params['transit_routing_preference'] =
transitRoutingPreference.toApiString();
}
if (apiKey != null) {
params['key'] = apiKey!;
}
return url.replace(queryParameters: params).toString();
}