Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Quando determini il percorso migliore per un viaggio in ridesharing, il
percorso più veloce potrebbe non essere sempre l'opzione migliore. Potresti voler
pianificare il tuo percorso.
L'API Routes Preferred ti consente di pianificare un itinerario specificando
un obiettivo dell'itinerario utilizzando il metodo ComputeCustomRoutes.
Il metodo ComputeCustomRoutes può anche contribuire alla conformità del percorso consentendo di ridurre al minimo la differenza tra il percorso selezionato dall'operatore e quello percorso.
Utilizza sia l'API Routes Preferred sia l'SDK Navigation per sfruttare appieno i vantaggi della pianificazione del percorso.
Abilita il metodo ComputeCustomRoutes
Prima di poter utilizzare il metodo ComputeCustomRoutes nel tuo codice, devi
attivarlo. Per ulteriori informazioni sull'abilitazione dei metodi dell'API Routes Preferred, consulta la Guida introduttiva.
Utilizzare il metodo ComputeCustomRoutes
Il metodo ComputeCustomRoutes richiede di specificare una maschera del campo di risposta nell'input. Puoi fornire la maschera del campo di risposta utilizzando
il parametro URL $fields o fields oppure l'intestazione HTTP/gRPC
X-Goog-FieldMask. Per ulteriori informazioni, vedi
Parametri di sistema.
Il valore della maschera del campo è un elenco separato da virgole di percorsi dei campi. Ogni percorso del campo
è un elenco di nomi di campi separati da punti che rappresentano la gerarchia del messaggio.
Un nome di campo è la chiave dell'oggetto JSON o il nome del tag del campo protobuf.
Il percorso del campo inizia dal tipo di messaggio di risposta di primo livello
ed è facoltativamente seguito da uno o più punti e poi dal livello successivo
del nome del campo. In generale, i percorsi dei campi vengono creati nel seguente modo:
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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)."]]