Table of Contents

Class RoutesRequest

Namespace
GoogleMapsApi.Entities.Routes.Request
Assembly
GoogleMapsApi.dll

Request for the Google Routes API (POST https://routes.googleapis.com/directions/v2:computeRoutes). Modern replacement for the legacy Directions API: real-time traffic, eco-routing, toll calculation, two-wheeled vehicle support, and route alternatives.

public sealed class RoutesRequest : MapsBaseRequest
Inheritance
RoutesRequest
Inherited Members

Remarks

The Routes API requires a field mask. FieldMask is pre-populated with a reasonable default that mirrors what the legacy Directions API returned; tighten it to reduce response size and cost. See https://developers.google.com/maps/documentation/routes/choose_fields.

Fields

DefaultFieldMask

Default FieldMask — sized to roughly match what Directions returned.

public const string DefaultFieldMask = "routes.duration,routes.distanceMeters,routes.polyline.encodedPolyline,routes.legs.steps,routes.legs.distanceMeters,routes.legs.duration,routes.warnings"

Field Value

string

Properties

ArrivalTime

Desired arrival time in absolute time. Transit only; mutually exclusive with DepartureTime.

public DateTimeOffset? ArrivalTime { get; set; }

Property Value

DateTimeOffset?

ComputeAlternativeRoutes

If true, the API may return up to two additional alternative routes.

public bool ComputeAlternativeRoutes { get; set; }

Property Value

bool

DepartureTime

Desired departure time in absolute time. Mutually exclusive with ArrivalTime. Required for Transit unless ArrivalTime is set.

public DateTimeOffset? DepartureTime { get; set; }

Property Value

DateTimeOffset?

Destination

Destination waypoint. Required.

public Waypoint Destination { get; set; }

Property Value

Waypoint

ExtraComputations

Optional extra computations (tolls, fuel consumption, traffic polyline).

public List<ExtraComputation>? ExtraComputations { get; set; }

Property Value

List<ExtraComputation>

FieldMask

Comma-separated response field mask. Required by the Routes API — requests with an empty mask are rejected. Passed in the URL as $fields.

public string FieldMask { get; set; }

Property Value

string

Intermediates

Intermediate waypoints, in order.

public List<Waypoint>? Intermediates { get; set; }

Property Value

List<Waypoint>

LanguageCode

BCP-47 language code for the response (e.g. "en-US").

public string? LanguageCode { get; set; }

Property Value

string

OptimizeWaypointOrder

If true and intermediates are supplied, reorder them to minimize total cost.

public bool OptimizeWaypointOrder { get; set; }

Property Value

bool

Origin

Origin waypoint. Required.

public Waypoint Origin { get; set; }

Property Value

Waypoint

PolylineEncoding

Wire format of the polyline returned for each route.

public PolylineEncoding? PolylineEncoding { get; set; }

Property Value

PolylineEncoding?

PolylineQuality

Quality of the polyline returned for each route.

public PolylineQuality? PolylineQuality { get; set; }

Property Value

PolylineQuality?

RegionCode

Two-letter CLDR region code used for region-specific routing (e.g. "US").

public string? RegionCode { get; set; }

Property Value

string

RequestedReferenceRoutes

Optional reference routes to compute alongside the default route (e.g. fuel-efficient).

public List<ReferenceRoute>? RequestedReferenceRoutes { get; set; }

Property Value

List<ReferenceRoute>

RouteModifiers

Conditions affecting the route (avoidances, vehicle info, toll passes).

public RouteModifiers? RouteModifiers { get; set; }

Property Value

RouteModifiers

RoutingPreference

How traffic data should be applied. Only valid for Drive and TwoWheeler.

public RoutingPreference? RoutingPreference { get; set; }

Property Value

RoutingPreference?

TrafficModel

Traffic model used when traffic-aware routing is enabled.

public TrafficModel? TrafficModel { get; set; }

Property Value

TrafficModel?

TransitPreferences

Transit-specific preferences. Transit only.

public TransitPreferences? TransitPreferences { get; set; }

Property Value

TransitPreferences

TravelMode

Travel mode. Defaults to Drive.

public RoutesTravelMode TravelMode { get; set; }

Property Value

RoutesTravelMode

Units

Distance units for the response.

public Units? Units { get; set; }

Property Value

Units?

Methods

GetRequestBody()

Builds the body to send with this request, or null for endpoints that use GET with query-string parameters only. Derived requests that target POST-based endpoints (for example, Address Validation) override this to return a JSON HttpContent; when the engine sees a non-null body it issues a POST instead of a GET.

protected override HttpContent? GetRequestBody()

Returns

HttpContent

The HTTP content to send, or null for a GET request.

GetUri()

Builds the absolute request URI, including scheme, base URL, and serialized query-string parameters.

public override Uri GetUri()

Returns

Uri

The fully composed URI to send to the Google Maps API.