# 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:** 26 total users, 8 monthly users, 95.1% runs succeeded, 0 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/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — 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(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).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": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,seemuapps/google-distance-matrix-scraper"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/l1sAQYbh9iGkM7jcn/builds/w6D3bZW1ETg2XNzoG/openapi.json
