Routes Preferred API provides performance-optimized versions of Directions APIs for ridesharing and deliveries use cases, with the ComputeRoutes and ComputeRouteMatrix (Preview) methods. The ComputeCustomRoutes method is deprecated and closed to new customers. The API is available only to select customers through Google sales.
Routes Preferred API: key facts
- Product: Routes Preferred API
- Also known as: Google Maps Platform Routes Preferred API, Routes Preferred
- Category: Routes
- Platform: Web service (REST)
- Runs on: Server (backend code)
- Launch stage: GA
- Lifecycle: Active
- Overview: Routes Preferred API overview
Routes Preferred API: when to use it
Use Routes Preferred API when:
- You build a ridesharing or deliveries solution and need routes with ETAs from a performance-optimized Directions service.
- You need to choose response fields and set a routing preference to trade route quality against response latency.
- You need distance and duration for many origin and destination pairs over streaming gRPC or REST (
ComputeRouteMatrix, Preview). - You need toll fee estimates, traffic on polylines, or two-wheeler routes as part of a route response.
Don't use Routes Preferred API when:
- Your project isn't approved for Routes Preferred API through Google sales. Use Routes API instead.
Routes Preferred API: setup
- Service to enable:
routespreferred.googleapis.com - Authentication: API key, OAuth 2.0
- Get started: Set up Routes Preferred API
- Reference: Routes Preferred API reference
- Policies: Routes Preferred API policies
Routes Preferred API: common mistakes
- Problem:
ComputeRoutesrequires a response field mask. Using the wildcard (*) or top-levelroutesin production increases latency, and latency can grow later when Google adds new response fields. Fix: Set theX-Goog-FieldMaskheader (or the$fields/fieldsURL parameter) to only the fields you need, for exampleroutes.duration,routes.distanceMeters,routes.polyline. See /maps/documentation/routes_preferred/choose_fields. - Problem:
ComputeRouteMatrixreturns stream elements in no guaranteed order, and errors can apply to single elements instead of the whole stream. Fix: Includestatusin the field mask (otherwise every element appearsOK), map each element back withoriginIndexanddestinationIndex, keep your origin and destination list order, and check thestatusof each element. See /maps/documentation/routes_preferred/compute_route_matrix. - Problem:
ComputeCustomRoutessupports onlyDRIVE(orTRAVEL_MODE_UNSPECIFIED) andTWO_WHEELERand doesn't supportviaintermediate waypoints; other travel modes orviawaypoints make the request fail. Fix: Use onlyDRIVEorTWO_WHEELERwithoutviawaypoints withComputeCustomRoutes, or useComputeRoutes. See /maps/documentation/routes_preferred/custom_routes. - Problem: Waypoint optimization in
ComputeRoutesisn't enabled by default, so requests that rely on it don't get optimized waypoint order. Fix: Contact Support with estimatedComputeRoutesQPM using waypoint optimization and the typical and maximum number of waypoints per request. See /maps/documentation/routes_preferred/waypoint_optimization_proxy_api.
Routes Preferred API: legacy and deprecated features
ComputeCustomRoutesmethod (Plan a Custom Route): Deprecated. Replacement:ComputeRoutesfor routing in Routes Preferred API, or Routes APIcomputeRoutes(or Route Optimization APIoptimizeTours/batchOptimizeTours) for Navigation SDK route tokens. Symptom: Closed to new customers;ComputeRoutesin Routes Preferred API doesn't return a Navigation SDK route token.
What you can do with Routes Preferred API
See the guides linked below for each task, or compare across products in the Capabilities Explorer.
- Compute performance-optimized routes and ETAs with configurable quality-versus-latency preferences. Note: Available only to select ridesharing and delivery customers approved through Google sales; most developers should use the Routes API. Requires an
X-Goog-FieldMaskheader (orfieldsURL parameter). - Calculate travel time and distance across an origin-destination matrix over streaming gRPC or REST. Preview Note: Available only to select ridesharing and delivery customers approved through Google sales; most developers should use the Routes API. Stream elements return out of order; include
statusin the field mask and map results withoriginIndexanddestinationIndex. - Estimate toll fees along a route or route matrix. Note: Available only to select ridesharing and delivery customers approved through Google sales; most developers should use the Routes API. Available in select regions; specify vehicle emission type and toll passes for accurate estimates.
- Return traffic speed intervals along a route polyline. Note: Available only to select ridesharing and delivery customers approved through Google sales; most developers should use the Routes API. Include both
polylineandspeedReadingIntervalsinX-Goog-FieldMask. - Compute routes tailored for two-wheeled motorized vehicles. Note: Available only to select ridesharing and delivery customers approved through Google sales; most developers should use the Routes API. Set
travelModetoTWO_WHEELER(distinct fromBICYCLE). - Configure waypoint modifiers for vehicle heading, side-of-road bias, pickup stopovers, and pass-through points. Note: Available only to select ridesharing and delivery customers approved through Google sales; most developers should use the Routes API.
headingandsideOfRoadcan't be used on the same waypoint. - Reorder intermediate route waypoints to reduce travel time. Experimental Note: Available only to select ridesharing and delivery customers approved through Google sales; most developers should use the Routes API. Not enabled by default (contact Support to enable). Requires stopover waypoints only (no
viawaypoints) androutes.optimizedIntermediateWaypointIndexin the field mask.