# Google Direction Scraper (`dev_bodex/google-direction-scraper`)

This actor automates extracting route directions from Google Maps. Using Node.js and Puppeteer, it retrieves travel routes, distances, and estimated times for various transport modes, offering structured data for navigation, logistics, or travel planning applications.

- **URL**: https://beta-securitybyobscurity.apify.com/dev\_bodex/google-direction-scraper.md
- **Developed by:** [Festus Befgrp](https://beta-securitybyobscurity.apify.com/dev_bodex) (community)
- **Categories:** Travel, Jobs
- **Stats:** 14 total users, 3 monthly users, 100.0% runs succeeded, 1 bookmarks
- **User rating**: No ratings yet

## Pricing

$25.00/month + usage

To use this Actor, you pay a monthly rental fee to the developer. The rent is subtracted from your prepaid usage every month after the free trial period.
You also pay for the Apify platform usage, which gets cheaper the higher Apify subscription plan you have.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#rental-actors

# README

## Google Direction Scraper

This Apify actor scrapes detailed directions from Google Maps, providing route information such as distance, travel time, and step-by-step instructions for various modes of transportation (driving, walking, cycling, public transport, etc.). This is useful for generating route data for apps, transportation analysis, or travel planning.

## Features

- **Input**: Provide starting and destination locations (either as addresses or coordinates).

- **Modes of Transport**: Supports multiple modes of transportation:
  **Driving**,
  **Walking**,
  **Cycling**,
  **Flight**,
  **Transit**,
  **Two Wheeler**,

- **Detailed Route Information**: Retrieves essential route details:
  **Total distance**,
  **Estimated travel time**,
  **Step-by-step directions (turn-by-turn)**,
  **Transportation mode (e.g., driving, walking, cycling)**,
  **Estimated arrival time for public transportation**,
  **Directions with Google Maps link**,

- **Output Formats**: Results are available in JSON format for easy integration and further use.

## How It Works

This actor queries Google Maps for directions between the specified origin and destination locations and parses the results to extract key details about the route, travel time, distance, and steps.

## Input

The input is a JSON object that includes the following fields:

```javascript
{
  "source": "New York",
  "destination": "Washington"
}
```

- **source**: The starting location for the route (can be an address or coordinates).
- **destination**: The destination location for the route (can be an address or coordinates).

## Output

The output is a JSON object containing detailed route information for the trip. Here’s an example of what the output might look like:

```javascript
[{
  "source": "New York",
  "destination": "Washington",
  "mode": {
    "best": [
      {
        "mode": "Driving",
        "duration": "43 hr",
        "metre": "2,919 miles",
        "direction": "via I-80 W",
        "means": null,
        "info": "43 hr without traffic\n This route has tolls.\n Your destination is in a different time zone."
      },
      {
        "mode": "Driving",
        "duration": "43 hr",
        "metre": "2,923 miles",
        "direction": "via I-40 W",
        "means": null,
        "info": "43 hr without traffic"
      },
      {
        "mode": "Flights",
        "duration": "7 hr 35 min",
        "metre": null,
        "direction": "New York, NY—Fresno, CA",
        "means": null,
        "info": null
      }
    ],
    "walk": [
      {
        "mode": "Walking",
        "duration": "1,033 hr",
        "metre": "2,830 miles",
        "direction": "via IA-2 E",
        "means": null,
        "info": " This route includes a ferry.\n This route has restricted usage or private roads.\n Your destination is in a different time zone."
      }
    ],
    "driving": [
      {
        "mode": "Driving",
        "duration": "43 hr",
        "metre": "2,919 miles",
        "direction": "via I-80 W",
        "means": null,
        "info": "43 hr without traffic\n This route has tolls.\n Your destination is in a different time zone."
      },
      {
        "mode": "Driving",
        "duration": "43 hr",
        "metre": "2,923 miles",
        "direction": "via I-40 W",
        "means": null,
        "info": "43 hr without traffic"
      },
      {
        "mode": "Driving",
        "duration": "43 hr",
        "metre": "2,954 miles",
        "direction": "via I-70 W",
        "means": null,
        "info": "43 hr without traffic"
      }
    ],
    "two-wheeler": null,
    "transit": null,
    "flight": [
      {
        "mode": "Flights",
        "duration": "7 hr 35 min+ - from $481",
        "metre": null,
        "direction": "New York, NY—Fresno, CA",
        "means": null,
        "info": null
      }
    ],
    "cycling": [
      {
        "mode": "Cycling",
        "duration": "296 hr",
        "metre": "3,533 miles",
        "direction": "via Empire State Trl",
        "means": null,
        "info": " This route includes a ferry.\n This route crosses through Canada.\n This route has restricted usage or private roads.\n Your destination is in a different time zone."
      }
    ]
  }
}]
```

## Key Scraped Data

- **Source:** Starting location.
- **Destination:** Final destination.
- **Distance:** Total distance of the route.
- \*\*Duration: Estimated travel time.
- **Mode of Transport:** Driving, walking, cycling, or transit.
- **Steps:** Turn-by-turn directions for each leg of the journey.

## Output Formats

JSON

## Usage

\#On the Apify Platform

1. Go to the Google Direction Scraper actor on Apify.
2. Click Try for Free.
3. Provide the origin, destination, and mode of transport.
4. Run the actor and wait for it to complete.
5. Download the results in your preferred format (JSON).

## Locally via Apify CLI

1. Install Apify CLI.
2. Run the actor locally using the following command:

```javascript
apify run your-username/google-direction-scraper --input='{"source": "New York", "destination": "Washington"}'
```

## Input Example

```javascript
{
  "source": "New York",
  "destination": "Washington"
}
```

This input will fetch the directions from New York to Washington.

## Use Cases

- **Travel and Route Planning:** Get detailed directions between locations for driving, walking, or public transport.
- **Logistics and Transportation:** Automate route generation for delivery services, ridesharing, or commuting apps.
- **Research and Analysis:** Extract travel time and distance data for city planning, transportation studies, or efficiency improvements.

## Limitations

1. Only fetches directions available via Google Maps.
2. Public transportation data may vary based on the region and time of day.

# Actor input Schema

## `source` (type: `string`):

The starting location.

## `destination` (type: `string`):

The ending location.

## Actor input object example

```json
{
  "source": "New York",
  "destination": "Washington"
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "source": "New York",
    "destination": "Washington"
};

// Run the Actor and wait for it to finish
const run = await client.actor("dev_bodex/google-direction-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "source": "New York",
    "destination": "Washington",
}

# Run the Actor and wait for it to finish
run = client.actor("dev_bodex/google-direction-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "source": "New York",
  "destination": "Washington"
}' |
apify call dev_bodex/google-direction-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=dev_bodex/google-direction-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Google Direction Scraper",
        "description": "This actor automates extracting route directions from Google Maps. Using Node.js and Puppeteer, it retrieves travel routes, distances, and estimated times for various transport modes, offering structured data for navigation, logistics, or travel planning applications.",
        "version": "0.0",
        "x-build-id": "EOFUJwLOeBW7pDTfH"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/dev_bodex~google-direction-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-dev_bodex-google-direction-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/dev_bodex~google-direction-scraper/runs": {
            "post": {
                "operationId": "runs-sync-dev_bodex-google-direction-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/dev_bodex~google-direction-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-dev_bodex-google-direction-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "source",
                    "destination"
                ],
                "properties": {
                    "source": {
                        "title": "Location source",
                        "type": "string",
                        "description": "The starting location."
                    },
                    "destination": {
                        "title": "Location destination",
                        "type": "string",
                        "description": "The ending location."
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
