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
Properties
ArrivalTime
Desired arrival time in absolute time. Transit only; mutually exclusive with DepartureTime.
public DateTimeOffset? ArrivalTime { get; set; }
Property Value
ComputeAlternativeRoutes
If true, the API may return up to two additional alternative routes.
public bool ComputeAlternativeRoutes { get; set; }
Property Value
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
Destination
Destination waypoint. Required.
public Waypoint Destination { get; set; }
Property Value
ExtraComputations
Optional extra computations (tolls, fuel consumption, traffic polyline).
public List<ExtraComputation>? ExtraComputations { get; set; }
Property Value
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
Intermediates
Intermediate waypoints, in order.
public List<Waypoint>? Intermediates { get; set; }
Property Value
LanguageCode
BCP-47 language code for the response (e.g. "en-US").
public string? LanguageCode { get; set; }
Property Value
OptimizeWaypointOrder
If true and intermediates are supplied, reorder them to minimize total cost.
public bool OptimizeWaypointOrder { get; set; }
Property Value
Origin
Origin waypoint. Required.
public Waypoint Origin { get; set; }
Property Value
PolylineEncoding
Wire format of the polyline returned for each route.
public PolylineEncoding? PolylineEncoding { get; set; }
Property Value
PolylineQuality
Quality of the polyline returned for each route.
public PolylineQuality? PolylineQuality { get; set; }
Property Value
RegionCode
Two-letter CLDR region code used for region-specific routing (e.g. "US").
public string? RegionCode { get; set; }
Property Value
RequestedReferenceRoutes
Optional reference routes to compute alongside the default route (e.g. fuel-efficient).
public List<ReferenceRoute>? RequestedReferenceRoutes { get; set; }
Property Value
RouteModifiers
Conditions affecting the route (avoidances, vehicle info, toll passes).
public RouteModifiers? RouteModifiers { get; set; }
Property Value
RoutingPreference
How traffic data should be applied. Only valid for Drive and TwoWheeler.
public RoutingPreference? RoutingPreference { get; set; }
Property Value
TrafficModel
Traffic model used when traffic-aware routing is enabled.
public TrafficModel? TrafficModel { get; set; }
Property Value
TransitPreferences
Transit-specific preferences. Transit only.
public TransitPreferences? TransitPreferences { get; set; }
Property Value
TravelMode
Travel mode. Defaults to Drive.
public RoutesTravelMode TravelMode { get; set; }
Property Value
Units
Distance units for the response.
public Units? Units { get; set; }
Property Value
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
nullfor 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.