To use Cloud Fleet Routing, you first need to create a Google Cloud project (if you don't already have one) with the email address that was added to the Cloud Fleet Routing API's allowlist. You also need to create a billing account and enable billing for the project.
Next, do the following steps in the Google Cloud console:
- Follow the instructions to Enable the Cloud Optimization API.
- If you plan to use the Google Map Platform's Distance Matrix API, enable the Google Maps for Fleet Routing.
Authenticating to the API
Fleeting Routing uses OAuth 2.0 for API authentication and authorization. Authentication is the process of determining the identity of a client. The Cloud Optimization API must already be enabled in the authenticated project.Client libraries can use Application Default Credentials to easily authenticate with Google APIs and send requests to those APIs. With Application Default Credentials, you can test your application locally and deploy it without changing the underlying code. For more information, see Authenticate for using client libraries.
gcloud auth application-default login gcloud config set project ${PROJECT_NAME} gcloud auth application-default set-quota-project ${PROJECT_NAME}
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/keyfile.json"
Send requests to the API
You can send requests to the Cloud Fleet Routing Service using either HTTP requests or the Google API Client Libraries. HTTP requests are the simpler option. You send the data for the problem in JSON format as a POST request. This provides an easy way to test the service or generate quick solutions to a single vehicle routing problem. For information about sending HTTP requests, see the Send HTTP requests with Python quickstart.
When deploying your production code, we recommend using the Google API Client Libraries for the following reasons:
- It provides a faster and more robust connection between your client and the API.
- You can build requests programmatically and conveniently with less code.
To set up and send requests using the Google API Client Libraries, refer to the quickstarts:
- Send requests with the API Client Library for Python
- Send requests with the API Client Library for Java