The Directions API demo

This demo shows you how to use the Directions API to get a set of driving directions from one location to another. You may run this demo at no charge. Running this demo alone does not exceed your monthly quota.

To use the Directions API, complete the required setup steps by clicking through the following tabs:

Step 1


  1. In the Google Cloud Console, on the project selector page, click Create Project to begin creating a new Cloud project.

    Go to the project selector page

  2. Make sure that billing is enabled for your Cloud project. Confirm that billing is enabled for your project.

    Google Cloud offers a $0.00 charge trial. The trial expires at either end of 90 days or after the account has accrued $300 worth of charges, whichever comes first. Cancel anytime. Google Maps Platform features a recurring $200 monthly credit. For more information, see Billing account credits and Billing.

Cloud SDK

gcloud projects create "PROJECT"

Read more about the Google Cloud SDK , Cloud SDK installation , and the following commands:

Step 2

To use Google Maps Platform, you must enable the APIs or SDKs you plan to use with your project.


Enable the Directions API

Cloud SDK

gcloud services enable \
    --project "PROJECT" \

Read more about the Google Cloud SDK , Cloud SDK installation , and the following commands:

Step 3

This step only goes through the API Key creation process. If you use your API Key in production, we strongly recommend that you restrict your API key. You can find more information in the product-specific Using API Keys page.

The API key is a unique identifier that authenticates requests associated with your project for usage and billing purposes. You must have at least one API key associated with your project.

To create an API key:


  1. Go to the Google Maps Platform > Credentials page.

    Go to the Credentials page

  2. On the Credentials page, click Create credentials > API key.
    The API key created dialog displays your newly created API key.
  3. Click Close.
    The new API key is listed on the Credentials page under API keys.
    (Remember to restrict the API key before using it in production.)

Cloud SDK

gcloud alpha services api-keys create \
    --project "PROJECT" \
    --display-name "DISPLAY_NAME"

Read more about the Google Cloud SDK , Cloud SDK installation , and the following commands:

Getting directions

To receive driving directions from Disneyland to Universal Studios, Hollywood in JSON format, enter the URL into your web browser, and replace YOUR_API_KEY with your API Key:

You should receive the following JSON response:

       "geocoded_waypoints" : [
             "geocoder_status" : "OK",
             "place_id" : "ChIJRVY_etDX3IARGYLVpoq7f68",
             "types" : [
             "geocoder_status" : "OK",
             "partial_match" : true,
             "place_id" : "ChIJp2Mn4E2-woARQS2FILlxUzk",
             "types" : [ "route" ]
       "routes" : [
             "bounds" : {
                "northeast" : {
                   "lat" : 34.1330949,
                   "lng" : -117.9143879
                "southwest" : {
                   "lat" : 33.8068768,
                   "lng" : -118.3527671
             "copyrights" : "Map data ©2016 Google",
             "legs" : [
                   "distance" : {
                      "text" : "35.9 mi",
                      "value" : 57824
                   "duration" : {
                      "text" : "51 mins",
                      "value" : 3062
                   "end_address" : "Universal Studios Blvd, Los Angeles, CA 90068, USA",
                   "end_location" : {
                      "lat" : 34.1330949,
                      "lng" : -118.3524442
                   "start_address" : "Disneyland (Harbor Blvd.), S Harbor Blvd, Anaheim, CA 92802, USA",
                   "start_location" : {
                      "lat" : 33.8098177,
                      "lng" : -117.9154353

      ... Additional results shortened in this example[] ...

             "overview_polyline" : {
                "points" : "knjmEnjunUbKCfEA?_@]@kMBeE@qIIoF@wH@eFFk@WOUI_@?u@j@k@`@EXLTZHh@Y`AgApAaCrCUd@cDpDuAtAoApA{YlZiBdBaIhGkFrDeCtBuFxFmIdJmOjPaChDeBlDiAdD}ApGcDxU}@hEmAxD}[tt@yNb\\yBdEqFnJqB~DeFxMgK~VsMr[uKzVoCxEsEtG}BzCkHhKWh@]t@{AxEcClLkCjLi@`CwBfHaEzJuBdEyEhIaBnCiF|K_Oz\\
             "summary" : "I-5 N and US-101 N",
             "warnings" : [],
             "waypoint_order" : []
       "status" : "OK"

Congratulations! You've successfully set up and called the Directions API to receive directions.

Cleaning up

You can delete your Google Cloud project to stop billing for all the resources used within that project.

  1. In the Google Cloud Console, go to the Manage resources page:

    Go to the Manage resources page

  2. If the project that you plan to delete is attached to an organization, select and expand the organization list at the top of the page.
  3. In the project list, select the project that you want to delete and click Delete.
  4. In the dialog, type the project ID and click Shut down to delete the project.

Next steps