Routes Preferred API quick reference

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

Routes Preferred API: common mistakes

  • Problem: ComputeRoutes requires a response field mask. Using the wildcard (*) or top-level routes in production increases latency, and latency can grow later when Google adds new response fields. Fix: Set the X-Goog-FieldMask header (or the $fields/fields URL parameter) to only the fields you need, for example routes.duration,routes.distanceMeters,routes.polyline. See /maps/documentation/routes_preferred/choose_fields.
  • Problem: ComputeRouteMatrix returns stream elements in no guaranteed order, and errors can apply to single elements instead of the whole stream. Fix: Include status in the field mask (otherwise every element appears OK), map each element back with originIndex and destinationIndex, keep your origin and destination list order, and check the status of each element. See /maps/documentation/routes_preferred/compute_route_matrix.
  • Problem: ComputeCustomRoutes supports only DRIVE (or TRAVEL_MODE_UNSPECIFIED) and TWO_WHEELER and doesn't support via intermediate waypoints; other travel modes or via waypoints make the request fail. Fix: Use only DRIVE or TWO_WHEELER without via waypoints with ComputeCustomRoutes, or use ComputeRoutes. See /maps/documentation/routes_preferred/custom_routes.
  • Problem: Waypoint optimization in ComputeRoutes isn't enabled by default, so requests that rely on it don't get optimized waypoint order. Fix: Contact Support with estimated ComputeRoutes QPM 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

  • ComputeCustomRoutes method (Plan a Custom Route): Deprecated. Replacement: ComputeRoutes for routing in Routes Preferred API, or Routes API computeRoutes (or Route Optimization API optimizeTours / batchOptimizeTours) for Navigation SDK route tokens. Symptom: Closed to new customers; ComputeRoutes in 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.