# Google Distance Matrix Scraper (`seemuapps/google-distance-matrix-scraper`) Actor

Calculate travel time, distance, and traffic-aware ETAs between any list of origins and destinations using the official Google Distance Matrix API.

- **URL**: https://apify.com/seemuapps/google-distance-matrix-scraper.md
- **Developed by:** [Andrew](https://apify.com/seemuapps) (community)
- **Categories:** AI, Automation, Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, NaN bookmarks
- **User rating**: No ratings yet

## Pricing

from $12.00 / 1,000 origin destination pairs

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

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

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## Google Distance Matrix Scraper

Bulk-calculate travel time and distance between any list of origins and destinations using the official Google Distance Matrix API. Get traffic-aware driving ETAs, transit fares, walking and cycling times — one dataset row per origin×destination pair.

### What you get

- **One dataset row per origin×destination pair** — every origin paired with every destination
- **Travel distance** in meters and human-readable text
- **Travel duration** in seconds and human-readable text
- **Traffic-aware ETAs** when you set a departure time — duration in traffic for driving mode
- **Transit fares** with value and currency when mode is Transit
- **All four travel modes** — driving, walking, bicycling, transit
- **Auto-chunking** — large matrices are automatically split into 10×10 batches to respect Google's 100-element-per-request limit, then merged back into one dataset
- **Per-pair error handling** — bad inputs or unreachable pairs get a row with `status` like `NOT_FOUND` or `ZERO_RESULTS`; the run continues

### Use cases

- **Delivery & logistics routing** — pre-calculate drive times from warehouses to every customer, traffic included
- **Site selection** — find the candidate location with the shortest average drive time to a list of points of interest
- **Field service dispatch** — match technicians to jobs by drive time
- **Real estate commute analysis** — calculate transit/drive time from listings to a list of workplaces, gyms, schools
- **Bulk ETA APIs** — feed your CRM with up-to-date drive times to every account
- **Travel research** — compare driving vs transit vs cycling time for a list of trips

### How to use

1. Paste your **Origins** — addresses or `lat,lng` pairs, one per line.
2. Paste your **Destinations** — addresses or `lat,lng` pairs, one per line.
3. Pick a **Travel mode** — Driving, Walking, Bicycling, or Transit.
4. (Optional) Toggle **Units** between Metric (km) and Imperial (mi).
5. (Optional) For traffic-aware driving, set **Departure time** to `now` or a Unix-epoch timestamp.
6. (Optional) For transit, set **Departure time** or **Arrival time** and pick **Transit modes** (bus, subway, etc.).
7. (Optional) Set **Avoid** to exclude tolls, highways, ferries, or indoor segments.
8. Run — every origin×destination pair appears as its own row, ready to export as CSV or JSON.

### Examples

**Drive-time matrix for a small fleet:**
- Origins: 3 warehouse addresses
- Destinations: 50 customer addresses
- Result: 150 rows, each with driving distance and ETA

**Transit fare comparison for one trip across cities:**
- Origins: `Penn Station, NYC`
- Destinations: `Times Square, NYC`, `JFK Airport, NYC`, `Brooklyn Museum, NYC`
- Mode: Transit · Departure time: `now`
- Result: 3 rows with transit duration and fare per destination

**Traffic-aware drive time at rush hour:**
- Set **Departure time** to a future epoch timestamp (e.g. tomorrow 8 AM)
- Set **Traffic model** to `pessimistic` for worst-case ETAs

### Output schema

| Field | Type | Description |
|---|---|---|
| `origin` | string | Input origin |
| `destination` | string | Input destination |
| `originResolved` | string \| null | Google's resolved origin address |
| `destinationResolved` | string \| null | Google's resolved destination address |
| `mode` | string | Travel mode used |
| `status` | string | `OK`, `NOT_FOUND`, `ZERO_RESULTS`, `MAX_ROUTE_LENGTH_EXCEEDED`, `ERROR`, etc. |
| `distanceMeters` | number \| null | Distance in meters |
| `distanceText` | string \| null | Human-readable distance ("3.2 mi", "5.1 km") |
| `durationSeconds` | number \| null | Duration in seconds |
| `durationText` | string \| null | Human-readable duration ("12 mins", "1 hour 5 mins") |
| `durationInTrafficSeconds` | number \| null | Duration with traffic (driving + departureTime only) |
| `durationInTrafficText` | string \| null | Human-readable traffic duration |
| `fareValue` | number \| null | Transit fare value |
| `fareCurrency` | string \| null | Transit fare currency code |
| `fareText` | string \| null | Transit fare display text |
| `error` | string \| null | Error message if `status` is not `OK` |

### Tips

- **Cost scales with elements**, not requests — 25 origins × 25 destinations is 625 elements regardless of how many calls the actor makes under the hood.
- For traffic-aware ETAs you **must** set `departureTime` — without it, Google returns "typical" duration only.
- `duration_in_traffic` only appears for **driving** mode with **departureTime** set.
- `lat,lng` inputs skip address resolution and are slightly faster + more reliable than free-text addresses.
- For very large matrices (1000+ pairs), run multiple jobs in parallel — each Apify run handles its own chunking.

# Actor input Schema

## `origins` (type: `array`):

Origin addresses or 'lat,lng' pairs. The actor auto-chunks large lists into 10x10 batches to respect the API's 100-element-per-request limit.
## `destinations` (type: `array`):

Destination addresses or 'lat,lng' pairs. Every origin is paired with every destination, producing one dataset row per pair.
## `mode` (type: `string`):

How the route between each origin and destination is calculated. Use Transit for public-transport ETAs and fares.
## `units` (type: `string`):

Units used for the human-readable distance and duration text. Numeric meters and seconds are always returned alongside.
## `avoid` (type: `array`):

Features to avoid: tolls, highways, ferries, indoor. Driving/walking/bicycling modes only.
## `departureTime` (type: `string`):

Departure time for traffic-aware ETAs. Use 'now' or a Unix-epoch timestamp in seconds. Required for transit and for traffic-aware driving.
## `arrivalTime` (type: `string`):

Arrival time as a Unix-epoch timestamp in seconds. Transit mode only. Mutually exclusive with departure time.
## `trafficModel` (type: `string`):

Traffic prediction model. Only applied when Departure time is set and mode is driving.
## `transitMode` (type: `array`):

Transit modes to consider: bus, subway, train, tram, rail. Transit mode only.
## `language` (type: `string`):

BCP-47 language code for distance/duration text (e.g. en, es, fr).
## `region` (type: `string`):

Two-letter region code to bias address resolution (e.g. us, gb, de).

## Actor input object example

```json
{
  "origins": [
    "1600 Amphitheatre Pkwy, Mountain View, CA",
    "1 Apple Park Way, Cupertino, CA"
  ],
  "destinations": [
    "SFO Airport, San Francisco, CA",
    "Stanford University, CA"
  ],
  "mode": "driving",
  "units": "metric",
  "trafficModel": "best_guess",
  "language": "en"
}
````

# Actor output Schema

## `results` (type: `string`):

One record per origin×destination pair: origin, destination, originResolved, destinationResolved, mode, status, distanceMeters, distanceText, durationSeconds, durationText, durationInTrafficSeconds, durationInTrafficText, fareValue, fareCurrency, fareText, error.

# 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 = {
    "origins": [
        "1600 Amphitheatre Pkwy, Mountain View, CA",
        "1 Apple Park Way, Cupertino, CA"
    ],
    "destinations": [
        "SFO Airport, San Francisco, CA",
        "Stanford University, CA"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("seemuapps/google-distance-matrix-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 = {
    "origins": [
        "1600 Amphitheatre Pkwy, Mountain View, CA",
        "1 Apple Park Way, Cupertino, CA",
    ],
    "destinations": [
        "SFO Airport, San Francisco, CA",
        "Stanford University, CA",
    ],
}

# Run the Actor and wait for it to finish
run = client.actor("seemuapps/google-distance-matrix-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 '{
  "origins": [
    "1600 Amphitheatre Pkwy, Mountain View, CA",
    "1 Apple Park Way, Cupertino, CA"
  ],
  "destinations": [
    "SFO Airport, San Francisco, CA",
    "Stanford University, CA"
  ]
}' |
apify call seemuapps/google-distance-matrix-scraper --silent --output-dataset

```

## MCP server setup

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

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Google Distance Matrix Scraper",
        "description": "Calculate travel time, distance, and traffic-aware ETAs between any list of origins and destinations using the official Google Distance Matrix API.",
        "version": "1.0",
        "x-build-id": "gSHDuAHHv0Dxby1pH"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/seemuapps~google-distance-matrix-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-seemuapps-google-distance-matrix-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/seemuapps~google-distance-matrix-scraper/runs": {
            "post": {
                "operationId": "runs-sync-seemuapps-google-distance-matrix-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/seemuapps~google-distance-matrix-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-seemuapps-google-distance-matrix-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": [
                    "origins",
                    "destinations"
                ],
                "properties": {
                    "origins": {
                        "title": "Origins",
                        "type": "array",
                        "description": "Origin addresses or 'lat,lng' pairs. The actor auto-chunks large lists into 10x10 batches to respect the API's 100-element-per-request limit.",
                        "items": {
                            "type": "string"
                        }
                    },
                    "destinations": {
                        "title": "Destinations",
                        "type": "array",
                        "description": "Destination addresses or 'lat,lng' pairs. Every origin is paired with every destination, producing one dataset row per pair.",
                        "items": {
                            "type": "string"
                        }
                    },
                    "mode": {
                        "title": "Travel mode",
                        "enum": [
                            "driving",
                            "walking",
                            "bicycling",
                            "transit"
                        ],
                        "type": "string",
                        "description": "How the route between each origin and destination is calculated. Use Transit for public-transport ETAs and fares.",
                        "default": "driving"
                    },
                    "units": {
                        "title": "Units",
                        "enum": [
                            "metric",
                            "imperial"
                        ],
                        "type": "string",
                        "description": "Units used for the human-readable distance and duration text. Numeric meters and seconds are always returned alongside.",
                        "default": "metric"
                    },
                    "avoid": {
                        "title": "Avoid",
                        "type": "array",
                        "description": "Features to avoid: tolls, highways, ferries, indoor. Driving/walking/bicycling modes only.",
                        "items": {
                            "type": "string"
                        }
                    },
                    "departureTime": {
                        "title": "Departure time",
                        "type": "string",
                        "description": "Departure time for traffic-aware ETAs. Use 'now' or a Unix-epoch timestamp in seconds. Required for transit and for traffic-aware driving."
                    },
                    "arrivalTime": {
                        "title": "Arrival time (transit only)",
                        "type": "string",
                        "description": "Arrival time as a Unix-epoch timestamp in seconds. Transit mode only. Mutually exclusive with departure time."
                    },
                    "trafficModel": {
                        "title": "Traffic model",
                        "enum": [
                            "best_guess",
                            "pessimistic",
                            "optimistic"
                        ],
                        "type": "string",
                        "description": "Traffic prediction model. Only applied when Departure time is set and mode is driving.",
                        "default": "best_guess"
                    },
                    "transitMode": {
                        "title": "Transit mode",
                        "type": "array",
                        "description": "Transit modes to consider: bus, subway, train, tram, rail. Transit mode only.",
                        "items": {
                            "type": "string"
                        }
                    },
                    "language": {
                        "title": "Language",
                        "type": "string",
                        "description": "BCP-47 language code for distance/duration text (e.g. en, es, fr).",
                        "default": "en"
                    },
                    "region": {
                        "title": "Region",
                        "type": "string",
                        "description": "Two-letter region code to bias address resolution (e.g. us, gb, de)."
                    }
                }
            },
            "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
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
