Google Maps Directions API

Our Google Maps Directions API allows you to scrape directions results from Google Maps. The API is accessed through the following endpoint: /search?engine=google_maps_directions.

A user may query the following: https://serpapi.com/search?engine=google_maps_directions utilizing a GET request. Head to the playground for a live and interactive demo.

API Parameters

Search Query

start_addr

Optional

Parameter defines the address of the starting point for the direction you want to search. You can use anything that you would use in a regular Google Maps Directions search.

Alternatively, you can use start_data_id or start_coords.

end_addr

Optional

Parameter defines the address of the ending point for the direction you want to search. You can use anything that you would use in a regular Google Maps Directions search.

Alternatively, you can use end_data_id or end_coords.

Localization

gl

Optional

Parameter defines the country to use for the Google search. It's a two-letter country code. (e.g., us for the United States, uk for United Kingdom, or fr for France) Head to the Google countries page for a full list of supported Google countries.

hl

Optional

Parameter defines the language to use for the Google Maps Directions search. It's a two-letter language code. (e.g., en for English, es for Spanish, or fr for French). Head to the Google languages page for a full list of supported Google languages.

Advanced Google Maps Directions Parameters

travel_mode

Optional

Parameter defines the travel mode.
Available options:
6 - Best (Default)
0 - Driving
9 - Two-wheeler
3 - Transit
2 - Walking
1 - Cycling
4 - Flight

start_data_id

Optional

Parameter defines the data ID of the starting point for the direction you want to search. Find the data ID of a place using our Google Maps API.

Alternatively, you can use start_addr or start_coords.

end_data_id

Optional

Parameter defines the data ID of the ending point for the direction you want to search. Find the data ID of a place using our Google Maps API.

Alternatively, you can use end_addr or end_coords.

start_coords

Optional

Parameter defines the GPS coordinates of the starting point for the direction you want to search. The format is latitude,longitude. E.g. 30.197471099,-97.66635289.

Alternatively, you can use start_addr or start_data_id.

end_coords

Optional

Parameter defines the GPS coordinates of the ending point for the direction you want to search. The format is latitude,longitude. E.g. 30.197471099,-97.66635289.

Alternatively, you can use end_addr or end_data_id.

Advanced Options

distance_unit

Optional

Parameter defines the displayed distance unit.
Available options:
1 - miles
0 - km

avoid

Optional

Parameter defines avoid options.
Available options:
highways - Highways
tolls - Tolls
ferries - Ferries
You can also combine multiple options by joining them with a comma (e.g.: highways,tolls).

prefer

Optional

Parameter defines preferred transit options.
Available options:
bus - Bus
subway - Subway
train - Train
tram_light_rail - Tram and light rail
You can also combine multiple options by joining them with a comma (e.g.: subway,train).

Parameter works only if travel_mode parameter is set to: 3 (Transit)

route

Optional

Parameter defines route options.
Available options:
2 - Fewer transfers
3 - Less walking
4 - Wheelchair accessible

Parameter works only if travel_mode parameter is set to: 3 (Transit)

time

Optional

Parameter defines the time to travel.
Available options:
depart_at:xxxxxx - Specifies the departure time, where xxxxxx is the timestamp. E.g. depart_at:1698229538 specifies the departure time to 2023-10-25 10:25:38 GMT+0000

arrive_by:xxxxxx - Specifies the arrival time, where xxxxxx is the timestamp. E.g. arrive_by:1698229538 specifies the arrival time to 2023-10-25 10:25:38 GMT+0000

last_available - Takes the last available transit. This option works only if travel_mode parameter is set to: 3 (Transit)

Serpapi Parameters

engine

Required

Set parameter to google_maps_directions to use the Google Maps Directions API engine.

no_cache

Optional

Parameter will force SerpApi to fetch the Google Maps Directions results even if a cached version is already present. A cache is served only if the query and all parameters are exactly the same. Cache expires after 1h. Cached searches are free, and are not counted towards your searches per month. It can be set to false (default) to allow results from the cache, or true to disallow results from the cache. no_cache and async parameters should not be used together.

async

Optional

Parameter defines the way you want to submit your search to SerpApi. It can be set to false (default) to open an HTTP connection and keep it open until you got your search results, or true to just submit your search to SerpApi and retrieve them later. In this case, you'll need to use our Searches Archive API to retrieve your results. async and no_cache parameters should not be used together. async should not be used on accounts with Ludicrous Speed enabled.

zero_trace

Optional

Enterprise only. Parameter enables ZeroTrace mode. It can be set to false (default) or true. Enable this mode to skip storing search parameters, search files, and search metadata on our servers. This may make debugging more difficult.

api_key

Required

Parameter defines the SerpApi private key to use.

output

Optional

Parameter defines the final output you want. It can be set to json (default) to get a structured JSON of the results, or html to get the raw html retrieved.

API Results

JSON Results

JSON output includes structured data for directions results.

A search status is accessible through search_metadata.status. It flows this way: Processing -> Success || Error. If a search has failed, error will contain an error message. search_metadata.id is the search ID inside SerpApi.

HTML Results

This API does not have html response, just a text. search_metadata.prettify_html_file contains prettified version of result. It is displayed in playground.

API Examples

JSON structure overview

{
  ...
  "places_info": [
    {
      "address": "String - Address of the place",
      "data_id": "String - The Google Maps data ID of the place, can be used in other SerpApi's Google Maps engines",
      "gps_coordinates": {
        "latitude": "Numeric - Place latitude",
        "longitude": "Numeric - Place longitude"
      },
    }
  ],
  "directions": [
    {
      "travel_mode": "String - Travel mode of the direction",
      "via": "String - Title of the direction",
      "start_time": "String - Start time of the transit",
      "end_time": "String - End time of the transit",
      "distance": "Integer - Distance of the direction, in meters",
      "duration": "Integer - Duration of the direction, in seconds",
      "arrive_around": "Integer - Estimated timestamp of arrival",
      "leave_around": "Integer - Estimated timestamp of leaving",
      "typical_duration_range": "String - Estimated duration range of the direction",
      "formatted_distance": "String - Formatted string of the distance",
      "formatted_duration": "String - Formatted string of the duration",
      "formatted_arrive_around": "String - Formatted string of the estimated arrival time",
      "formatted_leave_around": "String - Formatted string of the estimated leaving time",
      "cost": "Integer - Cost of the transit",
      "currency": "String - Currency of the cost",
      "extensions": "Array - A list of extra information of the direction",
      // only available for `Walking` travel mode
      "elevation_profile": {
        "ascent": "Integer - Amount of ascent of the walking in meters",
        "descent": "Integer - Amount of descent of the walking, in meters",
        "max_altitude": "Integer - Maximum altitude of the walking, in meters",
        "min_altitude": "Integer - Minimum altitude of the walking, in meters",
        "formatted_ascent": "String - Formatted string of the ascent",
        "formatted_descent": "String - Formatted string of the descent",
        "formatted_max_altitude": "String - Formatted string of the maximum altitude",
        "formatted_min_altitude": "String - Formatted string of the minimum altitude",
      },
      // only available for `Flight` travel mode
      "flight": {
        "departure": "String - Name of the departing place",
        "arrival": "String - Name of the arriving place",
        "date": "String - Date of the travel",
        "round_trip_price": "Integer - Price of the round trip flight",
        "currency": "String - Currency of the price",
        "airlines": "Array - A list of airline names",
        "nonstop_duration": "String - Duration of the nonstop flight, in seconds",
        "formatted_nonstop_duration": "String - Formatted string of the nonstop duration",
        "connecting_duration": "String - Duration of the connecting flight, in seconds",
        "formatted_connecting_duration": "String - Formatted string of the connecting duration",
        "google_flights_link": "String - URL to Google Flights search",
      },
      "trips": [
        {
          "travel_mode": "String - Travel mode of the trip",
          "title": "String - Title of the trip",
          "distance": "Integer - Distance of the trip, in meters",
          "duration": "Integer - Duration of the trip, in seconds",
          "formatted_distance": "String - Formatted string of the distance",
          "formatted_duration": "String - Formatted string of the duration",
          "start_stop": "Hash - Info about the starting stop",
          "end_stop": "Hash - Info about the ending stop",
          "stops": "Array - Intermidiate stops between the starting and ending stops",
          "service_run_by": {
            "name": "String - Name of the service runner",
            "link": "String - URL to the service runner",
            "route_information": "String - URL to the route information",
          },
          "details": [
            {
              "title": "String - Title of the detail",
              "action": "String - Action name of the detail",
              "distance": "Integer - Distance of the detail, in meters",
              "duration": "Integer - Duration of the detail, in seconds",
              "formatted_distance": "String - Formatted string of the distance",
              "formatted_duration": "String - Formatted string of the duration",
              "geo_photo": "String - URL to the GEO photo of the detail",
              "gps_coordinates": {
                "latitude": "Numeric - Latitude of the detail",
                "longitude": "Numeric - Longitude of the detail"
              },
              "extensions": "Array - A list of extra information of the detail"
            }
          ],
        }
      ]
    }
  ],
  "durations": [
    {
      "travel_mode": "String - Name of the travel mode",
      "duration": "Integer - Duration of the travel mode, in seconds",
      "formatted_duration": "String - Formatted string of the duration",
    }
  ],
  ...
}

Example with typical directions and transit directions

Example with typical directions and transit directions

JSON Example

{
  "search_metadata": {
    "id": "653b24de15afff3a862b65b3",
    "status": "Success",
    "json_endpoint": "https://serpapi.com/searches/6bbeb04e383ea965/653b24de15afff3a862b65b3.json",
    "created_at": "2023-10-27 02:47:58 UTC",
    "processed_at": "2023-10-27 02:47:58 UTC",
    "google_maps_directions_url": "https://www.google.com/maps/dir/Austin-Bergstrom+International+Airport/5540+N+Lamar+Blvd%2C+Austin%2C+TX+78756/data=!3m1!4b1!4m14!4m13!1m5!1m1!1s0x8644b13b8b4aff45:0x1ca7fca8c9dc2768!2m2!1d-97.66635289999999!2d30.197471099999998!1m5!1m1!1s0x8644ca4259a4bacf:0x5782c78a0ae2d9a3!2m2!1d-97.7278869!2d30.3246388!3e6?hl=en",
    "raw_html_file": "https://serpapi.com/searches/6bbeb04e383ea965/653b24de15afff3a862b65b3.html",
    "prettify_html_file": "https://serpapi.com/searches/6bbeb04e383ea965/653b24de15afff3a862b65b3.prettify",
    "total_time_taken": 1.05
  },
  "search_parameters": {
    "engine": "google_maps_directions",
    "hl": "en",
    "start_addr": "Austin-Bergstrom International Airport",
    "end_addr": "5540 N Lamar Blvd, Austin, TX 78756, USA"
  },
  "places_info": [
    {
      "address": "Austin-Bergstrom International Airport",
      "data_id": "0x8644b13b8b4aff45:0x1ca7fca8c9dc2768",
      "gps_coordinates": {
        "latitude": 30.197471099999998,
        "longitude": -97.66635289999999
      }
    },
    {
      "address": "5540 N Lamar Blvd, Austin, TX 78756",
      "data_id": "0x8644ca4259a4bacf:0x5782c78a0ae2d9a3",
      "gps_coordinates": {
        "latitude": 30.3246388,
        "longitude": -97.7278869
      }
    }
  ],
  "directions": [
    {
      "travel_mode": "Driving",
      "via": "183 Toll",
      "distance": 21397,
      "duration": 970,
      "formatted_distance": "13.3 miles",
      "formatted_duration": "16 min",
      "extensions": [
        "Fastest route now due to traffic conditions",
        "This route has tolls."
      ],
      "trips": [
        {
          "travel_mode": "Driving",
          "title": "Get on  State Hwy 71 W  in  Del Valle  from  Hotel Dr  and  Spirit of Texas Dr",
          "distance": 1351,
          "duration": 139,
          "formatted_distance": "0.8 mi",
          "formatted_duration": "2 min",
          "details": [
            {
              "title": "Head  southwest  on  Presidential Blvd  toward  Service Dr",
              "action": "straight",
              "distance": 3,
              "duration": 0,
              "formatted_distance": "10 ft",
              "formatted_duration": "0 sec"
            },
            {
              "title": "Slight  right  onto  Service Dr",
              "action": "turn-slight-right",
              "distance": 147,
              "duration": 14,
              "formatted_distance": "482 ft",
              "formatted_duration": "14 sec"
            },
            ...
            {
              "title": "Turn  left  to merge onto  State Hwy 71 W",
              "action": "merge",
              "distance": 489,
              "duration": 41,
              "formatted_distance": "0.3 mi",
              "formatted_duration": "41 sec",
              "geo_photo": "https://geo0.ggpht.com/cbk?cb_client=unknown_client.gws&output=thumbnail&thumb=2&panoid=5VuJaV4okpHOIlrk6vjVzA&w=203&h=100&yaw=35&pitch=0&thumbfov=114&ll=30.215779,-97.663537",
              "gps_coordinates": {
                "latitude": 30.215778597115996,
                "longitude": -97.66353692926126
              }
            }
          ]
        },
        {
          "travel_mode": "Driving",
          "title": "Take  S Hwy 183  and  183 Toll  to  Ed Bluestein Blvd . Take exit  290  from  US-183 Hwy N",
          "distance": 13352,
          "duration": 452,
          "formatted_distance": "8.3 mi",
          "formatted_duration": "8 min",
          "details": [
            {
              "title": "Merge onto  State Hwy 71 W",
              "action": "merge",
              "distance": 883,
              "duration": 33,
              "formatted_distance": "0.5 mi",
              "formatted_duration": "33 sec",
              "geo_photo": "https://geo0.ggpht.com/cbk?cb_client=unknown_client.gws&output=thumbnail&thumb=2&panoid=6W9RImNO1oAtGmrY-BxRyA&w=203&h=100&yaw=271&pitch=0&thumbfov=114&ll=30.218076,-97.667626",
              "gps_coordinates": {
                "latitude": 30.218075561429668,
                "longitude": -97.66762618600264
              }
            },
            {
              "title": "Keep  left  to stay on  State Hwy 71 W",
              "action": "turn-left",
              "distance": 155,
              "duration": 6,
              "formatted_distance": "0.1 mi",
              "formatted_duration": "6 sec",
              "geo_photo": "https://geo0.ggpht.com/cbk?cb_client=unknown_client.gws&output=thumbnail&thumb=2&panoid=taShVzROLv_24piCVDKjVw&w=203&h=100&yaw=294&pitch=0&thumbfov=114&ll=30.221939,-97.675603",
              "gps_coordinates": {
                "latitude": 30.22193947835618,
                "longitude": -97.67560270002575
              }
            },
            ...
            {
              "title": "Take exit  290  to merge onto  Ed Bluestein Blvd",
              "action": "ramp-right",
              "distance": 396,
              "duration": 16,
              "formatted_distance": "0.2 mi",
              "formatted_duration": "16 sec",
              "geo_photo": "https://geo0.ggpht.com/cbk?cb_client=unknown_client.gws&output=thumbnail&thumb=2&panoid=-Kw5hYYw0gH0Ztaz83SYCQ&w=203&h=100&yaw=335&pitch=0&thumbfov=114&ll=30.316653,-97.663226",
              "gps_coordinates": {
                "latitude": 30.316653039874772,
                "longitude": -97.66322628500936
              }
            }
          ]
        },
        ...
      ]
    },
    {
      "travel_mode": "Transit",
      "via": "every 30 min",
      "start_time": "10:00 PM",
      "end_time": "11:01 PM",
      "distance": 20741,
      "duration": 3696,
      "formatted_distance": "12.9 miles",
      "formatted_duration": "1 hr 1 min",
      "cost": 2.5,
      "currency": "USD",
      "trips": [
        {
          "travel_mode": "Transit",
          "title": "20 Springdale NB",
          "duration": 1519,
          "formatted_duration": "25 min",
          "start_stop": {
            "name": "ABIA Lower Level",
            "stop_id": "4326",
            "time": "10:00 PM",
            "data_id": "0x8644b12fd58ade63:0xe4f74504ec3e0789"
          },
          "end_stop": {
            "name": "Vic Mathias/Auditorium Shores (NB)",
            "stop_id": "2767",
            "time": "10:25 PM",
            "data_id": "0x8644b50468dc089b:0xe538290c1b432609"
          },
          "stops": [
            {
              "name": "New Airport/Employee",
              "stop_id": "5099",
              "time": "10:02 PM",
              "data_id": "0x8644b6d2c44dff0d:0xb675564586691762"
            },
            {
              "name": "1766 71/Thornberry",
              "stop_id": "6241",
              "time": "10:03 PM",
              "data_id": "0x8644b6ceda7d81cd:0x8efd97972d53024d"
            },
            ...
            {
              "name": "150 Riverside/Newning",
              "stop_id": "1249",
              "time": "10:23 PM",
              "data_id": "0x8644b5010bcef057:0x6907542b89870119"
            }
          ],
          "service_run_by": {
            "name": "Capital Metro",
            "link": "http://www.capmetro.org/",
            "route_information": "http://www.capmetro.org/current_schedules/pdf/020.pdf"
          }
        },
        {
          "travel_mode": "Transit",
          "title": "801 Tech Ridge Park & Ride NB",
          "duration": 1440,
          "formatted_duration": "24 min",
          "start_stop": {
            "name": "Vic Mathias/Auditorium Shores (NB)",
            "stop_id": "2767",
            "time": "10:33 PM",
            "data_id": "0x8644b50468dc089b:0xe538290c1b432609"
          },
          "end_stop": {
            "name": "Brentwood Station (NB)",
            "stop_id": "5862",
            "time": "10:57 PM",
            "data_id": "0x8644ca43d075faeb:0x31501d1696f6b5c"
          },
          "stops": [
            {
              "name": "Republic Square Station (NB)",
              "stop_id": "5868",
              "time": "10:35 PM",
              "data_id": "0x8644b508c37bdb85:0xc78e875dbe69f8d8"
            },
            {
              "name": "Austin History Center",
              "stop_id": "2606",
              "time": "10:38 PM",
              "data_id": "0x8644b50bd358ff1d:0x1795bcf1bd51e0ca"
            },
            ...
            {
              "name": "North Loop East Station (NB)",
              "stop_id": "612",
              "time": "10:55 PM",
              "data_id": "0x8644ca68392c5cfd:0x502891f41f80d1cd"
            }
          ],
          "service_run_by": {
            "name": "Capital Metro",
            "link": "http://www.capmetro.org/",
            "route_information": "http://www.capmetro.org/current_schedules/pdf/801.pdf"
          }
        },
        {
          "travel_mode": "Walking",
          "title": "Walk",
          "distance": 307,
          "duration": 276,
          "formatted_distance": "0.2 mi",
          "formatted_duration": "4 min",
          "details": [
            {
              "title": "Head  southwest  on  N Lamar Blvd  toward  W Koenig Ln",
              "action": "straight",
              "distance": 244,
              "duration": 220,
              "formatted_distance": "0.2 mi",
              "formatted_duration": "4 min",
              "geo_photo": "https://geo0.ggpht.com/cbk?cb_client=unknown_client.gws&output=thumbnail&thumb=2&panoid=oWMCxXtS-0dz8QtPGrkW6Q&w=203&h=100&yaw=127&pitch=0&thumbfov=114&ll=30.326378,-97.726041",
              "gps_coordinates": {
                "latitude": 30.326378276258698,
                "longitude": -97.72604068429148
              },
              "extensions": [
                "Pass by KFC (on the left in 0.1 mi)"
              ]
            },
            {
              "title": "Turn  right",
              "action": "turn-right",
              "distance": 63,
              "duration": 56,
              "formatted_distance": "207 ft",
              "formatted_duration": "56 sec",
              "geo_photo": "https://geo0.ggpht.com/cbk?cb_client=unknown_client.gws&output=thumbnail&thumb=2&panoid=pww4A9lWzzbMyXgnHRaw_w&w=203&h=100&yaw=223&pitch=0&thumbfov=114&ll=30.324585,-97.727192",
              "gps_coordinates": {
                "latitude": 30.32458534013088,
                "longitude": -97.72719247999947
              },
              "extensions": [
                "Restricted usage road",
                "Destination will be on the left"
              ]
            }
          ]
        }
      ]
    },
    ...
  ],
  "durations": [
    {
      "travel_mode": "Driving",
      "duration": 970,
      "formatted_duration": "16 min"
    },
    {
      "travel_mode": "Transit",
      "duration": 3660,
      "formatted_duration": "1 hr 1"
    },
    {
      "travel_mode": "Walking",
      "duration": 21457,
      "formatted_duration": "6 hr"
    },
    {
      "travel_mode": "Cycling",
      "duration": 3615,
      "formatted_duration": "1 hr"
    }
  ]
}

Example with elevation_profile (Walking)

Example with elevation_profile (Walking)

JSON Example


{
  ...
  "directions": [
    {
      "travel_mode": "Walking",
      "via": "FM 969 E",
      "distance": 25946,
      "duration": 21457,
      "formatted_distance": "16.1 miles",
      "formatted_duration": "5 hr 58 min",
      "elevation_profile": {
        "ascent": 143,
        "descent": 80,
        "max_altitude": 209,
        "min_altitude": 123,
        "formatted_ascent": "469 ft",
        "formatted_descent": "262 ft",
        "formatted_max_altitude": "686 ft",
        "formatted_min_altitude": "404 ft"
      },
      "trips": [
        ...
      ],
    },
    {
      "travel_mode": "Walking",
      "via": "Airport Blvd",
      "distance": 31839,
      "duration": 26275,
      "formatted_distance": "19.8 miles",
      "formatted_duration": "7 hr 18 min",
      "elevation_profile": {
        "ascent": 131,
        "descent": 68,
        "max_altitude": 209,
        "min_altitude": 130,
        "formatted_ascent": "430 ft",
        "formatted_descent": "223 ft",
        "formatted_max_altitude": "686 ft",
        "formatted_min_altitude": "427 ft"
      },
      "trips": [
        ...
      ],
    },
    ...
  ],
  ...
}

Example with flight

Example with flight

JSON Example

{
  ...
  "directions": [
    {
      "travel_mode": "Flight",
      "flight": {
        "departure": "Federal Territory of Kuala Lumpur, Malaysia",
        "arrival": "Shanghai, China",
        "date": "Nov 24 – 28",
        "round_trip_price": 232.98,
        "currency": "USD",
        "airlines": [
          "Philippine Airlines",
          "China Southern",
          "China Eastern"
        ],
        "nonstop_duration": 18600,
        "formatted_nonstop_duration": "5 hr 10 min",
        "connecting_duration": 26400,
        "formatted_connecting_duration": "7 hr 20 min",
        "google_flights_link": "https://www.google.com/travel/flights?tfs=CAcQAhooEgoyMDIzLTExLTI0agwIAhIIL20vMDQ5ZDFyDAgCEggvbS8wNndqZhooEgoyMDIzLTExLTI4agwIAhIIL20vMDZ3amZyDAgCEggvbS8wNDlkMQ&source=maps&hl=en&authuser=0"
      }
    }
  ],
  ...
}

Example with arrive_around and typical_duration_range

Example with arrive_around and typical_duration_range

JSON Example

{
  ...
  "directions": [
    {
      "travel_mode": "Driving",
      "via": "183 Toll",
      "distance": 21397,
      "duration": 993,
      "arrive_around": 1698248619,
      "typical_duration_range": "15–18 min",
      "formatted_distance": "13.3 miles",
      "formatted_duration": "17 min",
      "formatted_arrive_around": "10:43 AM",
      "extensions": [
        "Fastest route now due to traffic conditions",
        "This route has tolls."
      ],
      "trips": [
        ...
      ]
    },
    {
      "travel_mode": "Driving",
      "via": "Airport Blvd",
      "distance": 15793,
      "duration": 1077,
      "arrive_around": 1698248851,
      "typical_duration_range": "16–20 min",
      "formatted_distance": "9.8 miles",
      "formatted_duration": "18 min",
      "formatted_arrive_around": "10:47 AM",
      "extensions": [
        "This route has tolls."
      ],
      "trips": [
        ...
      ]
    },
    ...
  ],
  ...
}