Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Lorsque vous choisissez le meilleur itinéraire pour un trajet en covoiturage, l'itinéraire le plus rapide n'est pas toujours la meilleure option. Vous pouvez planifier votre itinéraire.
L'API Routes Preferred vous permet de planifier un itinéraire en spécifiant un objectif d'itinéraire à l'aide de la méthode ComputeCustomRoutes.
La méthode ComputeCustomRoutes peut également vous aider à respecter les itinéraires en vous permettant de minimiser la différence entre l'itinéraire sélectionné par le conducteur et celui qu'il a emprunté.
Utilisez à la fois l'API Routes Preferred et le SDK Navigation pour profiter pleinement de la planification d'itinéraire.
Activer la méthode ComputeCustomRoutes
Avant de pouvoir utiliser la méthode ComputeCustomRoutes dans votre code, vous devez l'activer. Pour en savoir plus sur l'activation des méthodes de l'API Routes Preferred, consultez Premiers pas.
Utiliser la méthode ComputeCustomRoutes
La méthode ComputeCustomRoutes exige que vous spécifiiez un masque de champ de réponse dans l'entrée. Vous pouvez fournir le masque de champ de réponse à l'aide du paramètre d'URL $fields ou fields, ou à l'aide de l'en-tête HTTP/gRPC X-Goog-FieldMask. Pour en savoir plus, consultez Paramètres système.
La valeur du masque de champ est une liste de chemins de champ séparés par une virgule. Chaque chemin de champ est une liste de noms de champs séparés par un point, qui représentent la hiérarchie des messages.
Un nom de champ correspond à la clé de l'objet JSON ou au nom de balise du champ protobuf.
Le chemin d'accès au champ commence par le type de message de réponse de premier niveau, et est éventuellement suivi d'un ou plusieurs points, puis du nom du champ de niveau suivant. En règle générale, les chemins de champ sont construits de la manière suivante :
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/07/22 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Il n'y a pas l'information dont j'ai besoin","missingTheInformationINeed","thumb-down"],["Trop compliqué/Trop d'étapes","tooComplicatedTooManySteps","thumb-down"],["Obsolète","outOfDate","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Mauvais exemple/Erreur de code","samplesCodeIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/07/22 (UTC)."],[[["\u003cp\u003eThe Routes Preferred API's \u003ccode\u003eComputeCustomRoutes\u003c/code\u003e method enables planning routes based on objectives beyond the fastest route, such as compliance or driver preferences.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eComputeCustomRoutes\u003c/code\u003e supports optimizing routes for \u003ccode\u003eDRIVE\u003c/code\u003e and \u003ccode\u003eTWO_WHEELER\u003c/code\u003e travel modes, but excludes intermediate waypoints and other travel modes.\u003c/p\u003e\n"],["\u003cp\u003eUsing the Routes Preferred API with the Navigation SDK provides the best route planning outcomes, though they can utilize separate cloud projects.\u003c/p\u003e\n"],["\u003cp\u003eBefore using the \u003ccode\u003eComputeCustomRoutes\u003c/code\u003e method, enable it and verify your quota limits, requesting increases if necessary through Google Cloud Support.\u003c/p\u003e\n"],["\u003cp\u003eTo specify desired data in the response, use field masks with the \u003ccode\u003eComputeCustomRoutes\u003c/code\u003e method, selecting fields using dot-separated paths from the top-level response.\u003c/p\u003e\n"]]],["The Routes Preferred API's `ComputeCustomRoutes` method allows route planning by specifying a route objective and minimizing deviations from the operator's selected route. This method supports `DRIVE` and `TWO_WHEELER` travel modes, excluding `via` waypoints. To use it, enable the method and specify a response field mask via `$fields`, `fields`, or `X-Goog-FieldMask`. Quota limits should be monitored. Use alongside the Navigation SDK to maximize route planning benefits. Additionally, toll fees can be calculated using this API.\n"],null,["# Plan a Route\n\n\u003cbr /\u003e\n\n| This product or feature is in Preview (pre-GA). Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. Pre-GA Offerings are covered by the [Google\n| Maps Platform Service Specific Terms](https://cloud.google.com/maps-platform/terms/maps-service-terms). For more information, see the [launch stage\n| descriptions](/maps/launch-stages).\n\n\u003cbr /\u003e\n\nWhen you are determining the best route for a ridesharing trip, the\nfastest route may not always be the best option. You may want\nto plan your route.\n\nThe Routes Preferred API lets you plan a route by specifying\na route objective using the `ComputeCustomRoutes` method.\n\nThe `ComputeCustomRoutes` method can also help with route compliance by letting\nyou minimize the difference between the route selected by the operator and the\nroute driven.\n\nUse both the Routes Preferred API and the\n[Navigation SDK](https://developers.google.com/maps/documentation/navigation-sdk)\nto realize the full benefit of route planning.\n| **Note:** You do not have to use the same cloud project for the Routes Preferred API and the Navigation SDK.\n| **Note:** Unlike `ComputeRoutes` API, `ComputeCustomRoutes` only supports two travel modes, `DRIVE` (or the equivalent `TRAVEL_MODE_UNSPECIFIED`) and `TWO_WHEELER`. This method also does not support `via` intermediate waypoints. If you try to use other travel modes or `via` waypoints, the request fails. For more information about `via` waypoints, see [Routes Preferred API waypoints](/maps/documentation/routes_preferred/reference/rest/Shared.Types/Waypoint).\n\nEnable the ComputeCustomRoutes method\n-------------------------------------\n\nBefore you can use the `ComputeCustomRoutes` method in your code, you must\nenable it. For more information on enabling Routes Preferred API\nmethods, see [Getting Started](/maps/documentation/routes_preferred/get_started).\n| **Important:** Check your quota limits for Routes Preferred API methods. If you need to increase your quota limits, contact support by filing a case on the [Google Maps Platform support page](https://console.cloud.google.com/google/maps-apis/support) in the Google Cloud Console, or by calling the [Google Cloud Support Hotline](/maps/documentation/routes_preferred/support#support_hotline).\n\nUse the ComputeCustomRoutes method\n----------------------------------\n\nThe `ComputeCustomRoutes` method requires that you specify a response\nfield mask in the input. You can provide the response field mask by using\nthe URL parameter `$fields` or `fields`, or by using the HTTP/gRPC header\n`X-Goog-FieldMask`. For more information, see\n[System Parameters](https://cloud.google.com/apis/docs/system-parameters).\n\nThe field mask value is a comma-separated list of field paths. Each field path\nis a dot-separated list of field names that represent the message hierarchy.\nA field name is either the JSON object key, or the protobuf field tag name.\nThe field path starts from the top level response message type,\nand is optionally followed by one or more dots, and then the next level\nof field name. In general, field paths are constructed in the following way: \n\n```\ntopLevelField[.secondLevelField][.thirdLevelField][...]\n```\n\nA special case field mask is a wildcard \"\\*\", which selects all root-level\nfields.\n\nFor more information, see:\n\n- [**gRPC API reference**](/maps/documentation/routes_preferred/reference/rpc/google.maps.routes.v1)\n- [**REST API reference**](/maps/documentation/routes_preferred/reference/rest/v1/TopLevel/computeCustomRoutes)\n\nFor examples of using the `ComputeCustomRoutes` method, see\n[Computing a Custom Route (Beta) Examples](/maps/documentation/routes_preferred/custom_route_examples).\n\nCalculating toll fees\n---------------------\n\nFor information on calculating toll fees, see\n[Calculate toll fees](/maps/documentation/routes_preferred/calculate_toll_fees).\n\nFor examples of calculating toll fees, see\n[Computing a Custom Route Examples](/maps/documentation/routes_preferred/custom_route_examples#toll-fee-examples)."]]