Skip to main content

Route results

GetRoutesAsync returns a RouteResult. It holds one or more routes; each route is split into legs, each leg into steps, and transit steps carry their line, stops and times. How much of this is filled depends on the detail level.

Example​

Here request is a RouteRequest built as on Directions:

using AarxMaps.Routes.Common.Models;
using AarxMaps.Routes.Services.Directions;

var result = await routes.Directions.GetRoutesAsync(
request, RouteDetailLevel.Full, ct);

var main = result.Routes.FirstOrDefault(
r => r.Labels.Contains(RouteLabel.DefaultRoute));
if (main is null) {
return; // no route between the waypoints
}

Console.WriteLine($"{main.DistanceMeters} m, {main.Duration}");
foreach (var leg in main.Legs) {
foreach (var step in leg.Steps) {
Console.WriteLine(step.NavigationInstruction?.Instructions);
}
}
Name clash in ASP.NET Core

Route also exists as Microsoft.AspNetCore.Routing.Route, which ASP.NET Core projects import by default. Use var, as above, or add an alias: using Route = AarxMaps.Routes.Services.Directions.Route;.

Route result​

PropertyTypeNotes
RoutesIReadOnlyList<Route>Empty when no route exists
FallbackInfoFallbackInfo?Set when Google couldn't honor the routing preference

The main route is the one labeled RouteLabel.DefaultRoute, normally the first. With WithAlternativeRoutes there are up to three routes in total.

RouteLabelMeaning
DefaultRouteThe main route
DefaultRouteAlternateAn alternative to the main route
FuelEfficientA route optimized for fuel consumption
ShorterDistanceA route optimized for travel distance

Route​

Route, most-used properties:

PropertyTypeNotes
LabelsIReadOnlyList<RouteLabel>See above
DistanceMetersint
DurationTimeSpanWith traffic when requested
StaticDurationTimeSpanWithout traffic
EncodedPolylinestring?Standard and Full
ViewportViewport?Standard and Full
LegsIReadOnlyList<RouteLeg>Standard and Full
LocalizedValuesRouteLocalizedValues?Display text
All properties
PropertyTypeNotes
LabelsIReadOnlyList<RouteLabel>
DistanceMetersint
DurationTimeSpanEquals StaticDuration without traffic
StaticDurationTimeSpan
Descriptionstring?For example the main road
WarningsIReadOnlyList<string>Show them with the route
ViewportViewport?Low (south-west), High (north-east)
EncodedPolylinestring?
LegsIReadOnlyList<RouteLeg>
OptimizedWaypointOrderIReadOnlyList<int>See Intermediates
TravelAdvisoryRouteTravelAdvisory?See below
LocalizedValuesRouteLocalizedValues?
RouteTokenstring?Full only

RouteToken is an opaque token that lets the Google Navigation SDK rebuild this exact route.

Legs​

There is one leg between every two consecutive waypoints that aren't via waypoints. Standard fills the totals, the start and end locations and the localized values; Full fills everything.

PropertyTypeNotes
DistanceMetersint
DurationTimeSpanWith traffic when requested
StaticDurationTimeSpanWithout traffic
StartLocationLocation?The waypoint, snapped to the road
EndLocationLocation?The waypoint, snapped to the road
EncodedPolylinestring?Full only
StepsIReadOnlyList<RouteStep>Full only
SegmentsIReadOnlyList<MultiModalSegment>Full, transit only
LocalizedValuesRouteLegLocalizedValues?Display text

Steps​

A step is one navigation instruction, such as a turn.

PropertyTypeNotes
DistanceMetersint
StaticDurationTimeSpanSteps have no traffic duration
StartLocationLocation?
EndLocationLocation?
EncodedPolylinestring?
NavigationInstructionNavigationInstruction?What to do
LocalizedValuesRouteLegStepLocalizedValues?Display text
TravelModeTravelMode
TransitDetailsTransitDetails?Transit steps only

NavigationInstruction has Instructions (string?, for example "Turn left onto Main St", in the request language) and Maneuver, the action to take, for example to pick an icon.

All Maneuver values

Unknown, TurnSlightLeft, TurnSharpLeft, UturnLeft, TurnLeft, TurnSlightRight, TurnSharpRight, UturnRight, TurnRight, Straight, RampLeft, RampRight, Merge, ForkLeft, ForkRight, Ferry, FerryTrain, RoundaboutLeft, RoundaboutRight, Depart, NameChange, Destination.

Transit​

In a transit route, steps alternate between TravelMode.Walk and TravelMode.Transit. Only transit steps have TransitDetails:

using AarxMaps.Routes.Services.Directions;

foreach (var step in leg.Steps) {
if (step.TransitDetails is not { } transit) {
continue;
}

Console.WriteLine(
$"{transit.Line?.ShortName} to {transit.Headsign}: " +
$"{transit.DepartureStop?.Name} at {transit.DepartureTimeText}, " +
$"{transit.StopCount} stops");
}
PropertyTypeNotes
DepartureStopTransitStop?Where to board
ArrivalStopTransitStop?Where to leave
DepartureTimeDateTimeOffset?UTC
ArrivalTimeDateTimeOffset?UTC
DepartureTimeTextstring?Local time at the stop
ArrivalTimeTextstring?Local time at the stop
Headsignstring?Direction shown on the vehicle
StopCountintIncludes the arrival stop
LineTransitLine?
Stops, lines and agencies

TransitStop: Name (string?) and Location (LatLng?).

TransitLine: Name and ShortName (for example "M7"), Color and TextColor (hex strings such as "#FF0000"), VehicleType (TransitVehicleType), VehicleName (in the request language), all string? except VehicleType, and Agencies (IReadOnlyList<TransitAgency>).

TransitAgency: Name (string?) and Uri (Uri?, http or https only). Show the agency names and links wherever you display transit directions.

TransitVehicleType: Unknown, Bus, CableCar, CommuterTrain, Ferry, Funicular, GondolaLift, HeavyRail, HighSpeedTrain, IntercityBus, LongDistanceTrain, MetroRail, Monorail, Other, Rail, ShareTaxi, Subway, Tram, Trolleybus.

Segments group consecutive steps that share a travel mode, for example a walk and then a bus ride. Each MultiModalSegment has StepStartIndex and StepEndIndex (indexes into Steps), a NavigationInstruction and a TravelMode.

Localized values​

Display text, formatted in the request language and units, for example "12.3 km" or "25 mins". Show it, don't parse it; use the numeric properties for math.

TypeUsed onProperties
RouteLocalizedValuesRoute, matrix elementDistance, Duration, StaticDuration, TransitFare
RouteLegLocalizedValuesLegDistance, Duration, StaticDuration
RouteLegStepLocalizedValuesStepDistance, StaticDuration

All of them are string?.

Advisories and fallback​

RouteTravelAdvisory (route level only):

  • RouteRestrictionsPartiallyIgnored (bool): Google ignored some requested restrictions, such as route modifiers, because no route satisfied all of them.
  • TransitFare (Money?): the total fare, only when Google knows the fare of every transit step. Money has CurrencyCode (ISO 4217, string?) and Amount (decimal).

FallbackInfo is set only when Google couldn't use the requested routing preference. Durations and traffic data then follow its RoutingMode:

PropertyValues
RoutingModeFallbackTrafficUnaware, FallbackTrafficAware
ReasonServerError, LatencyExceeded

Both enums also have Unknown.

Values​

  • Distances are meters, durations TimeSpan, timestamps DateTimeOffset in UTC.
  • Polylines are strings in Google's encoded polyline format. The SDK has no decoder; see Known limitations.
  • Google leaves out zero values, so they read as 0 or false. A missing object is null; a list is empty, never null.
  • Location (start and end points) has LatLng and an optional Heading (int?).

See also​