# Google Maps Traffic Scraper (`romy/google-maps-traffic-scraper`) Actor

Fetch real-time and historical traffic data from Google Maps as GeoJSON. Returns road-level speed levels, congestion status, and road segments for any coordinate and zoom level.

- **URL**: https://apify.com/romy/google-maps-traffic-scraper.md
- **Developed by:** [Romy](https://apify.com/romy) (community)
- **Categories:** Automation, Developer tools, Integrations
- **Stats:** 21 total users, 2 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $5.00 / 1,000 tile fetcheds

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

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 Traffic Scraper

Fetch real-time traffic data from Google Maps as GeoJSON — road-level speed levels, congestion status, and road segments for any coordinate and zoom level.

Powered by Google Maps internal tile API. Data is returned as a **GeoJSON FeatureCollection** with LineString geometries, ready to plug into Mapbox, Leaflet, QGIS, or any GIS tool.

---

### Input

```json
{
  "lat": "-6.219320790773214",
  "lon": "106.81002294222947",
  "zoom": 17,
  "radius": 2,
  "seconds": 391039
}
````

| Field     | Type   | Required | Description                                        |
| --------- | ------ | -------- | -------------------------------------------------- |
| `lat`     | string | ✅       | Latitude of the center point                       |
| `lon`     | string | ✅       | Longitude of the center point                      |
| `zoom`    | int    | ✅       | Map zoom level (10–20). Higher = more detail       |
| `radius`  | int    | ✅       | Tile radius around center. Total tiles = `(2r+1)²` |
| `seconds` | int    | ❌       | Seconds into week (see below). `-1` = current time |

***

#### `zoom` — choosing the right level

| Zoom  | Coverage per tile  | Best for                           |
| ----- | ------------------ | ---------------------------------- |
| 10–12 | City-wide          | Heatmap, macro overview            |
| 13–15 | District / kawasan | Area analysis                      |
| 16–17 | Street level       | Per-road congestion ✅ recommended |
| 18–20 | Lane level         | High-detail, niche use cases       |

> **Recommended:** `zoom: 17` for street-level detail with reasonable tile count.

***

#### `radius` — area coverage

Radius controls how many tiles are fetched around the center point.

| Radius | Tiles fetched | Approx. area (zoom 17)        |
| ------ | ------------- | ----------------------------- |
| 0      | 1             | ~300m × 300m                  |
| 1      | 9             | ~900m × 900m                  |
| 2      | 25            | ~1.5km × 1.5km ✅ recommended |
| 3      | 49            | ~2.2km × 2.2km                |
| 5      | 121           | ~3.7km × 3.7km                |

> Higher radius = more HTTP requests = higher cost and longer run time.

***

#### `seconds` — historical traffic

Pass `-1` to get **current live traffic**.

To fetch traffic for a **specific time in the week**, convert a datetime to seconds-into-week (Sunday 00:00 UTC = 0):

```python
from datetime import datetime, timezone

def datetime_to_seconds_into_week(dt: datetime) -> int:
    """Convert datetime (aware) → seconds_into_week (Sunday 00:00 UTC = 0)."""
    dt_utc  = dt.astimezone(timezone.utc)
    day_utc = (dt_utc.weekday() + 1) % 7   # Sun=0, Mon=1, ..., Sat=6
    return (day_utc * 86400
            + dt_utc.hour   * 3600
            + dt_utc.minute * 60
            + dt_utc.second)

## Example: Monday 08:00 WIB (UTC+7) → UTC = Monday 01:00
dt = datetime(2024, 1, 8, 8, 0, 0, tzinfo=timezone.utc)  # already UTC here
seconds = datetime_to_seconds_into_week(dt)
## → 86400 + 3600 = 90000  (Monday 01:00 UTC)
```

> **Note:** Google Maps traffic data is based on historical weekly patterns. The `seconds` value represents a point in the weekly cycle, not an absolute timestamp — so the same value will return the same traffic pattern every week.

***

### Output

Returns a **GeoJSON FeatureCollection**:

![Screenshot-2026-02-23-005343](https://i.ibb.co.com/wZdFVYYF/Screenshot-2026-02-23-005343.png)
![Screenshot-2026-02-23-005418](https://i.ibb.co.com/tw3kKQ1B/Screenshot-2026-02-23-005418.png)

```json
{
  "type": "FeatureCollection",
  "metadata": {
    "center_lat": -6.219320790773214,
    "center_lon": 106.81002294222947,
    "zoom": 17,
    "tile_radius": 2,
    "tiles_fetched": 25,
    "total_features": 487,
    "seconds_in_week": 391039,
    "speed_summary": {
      "Free Flow": 210,
      "Slow Traffic": 180,
      "Heavy Congestion": 97
    }
  },
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [106.8100123, -6.2193456],
          [106.8101234, -6.2194567]
        ]
      },
      "properties": {
        "speed_level": 2,
        "speed_label": "Slow Traffic",
        "color": "#FF8C00",
        "road_class": 32,
        "stroke_weight": 5,
        "seconds_in_week": 391039
      }
    }
  ]
}
```

#### Speed levels

| `speed_level` | Label               | Color        |
| ------------- | ------------------- | ------------ |
| 1             | Free Flow           | `#2DB82D` 🟢 |
| 2             | Slow Traffic        | `#FF8C00` 🟠 |
| 3             | Moderate Congestion | `#FF4500` 🔴 |
| 4             | Heavy Congestion    | `#CC0000` 🔴 |
| 6             | Road Closed         | `#000000` ⚫ |

***

### Pricing

This Actor uses **Pay Per Event** billing — you only pay for what you use.

| Event               | Price    | Description                  |
| ------------------- | -------- | ---------------------------- |
| `apify-actor-start` | $0.00005 | Per run start                |
| `tile-fetched`      | $0.010   | Per tile fetched from Google |

Cost is fully **predictable before you run** — it depends only on the `radius` you choose:

| Radius | Tiles | Cost per request |
| ------ | ----- | ---------------- |
| 0      | 1     | ~$0.01           |
| 1      | 9     | ~$0.09           |
| 2      | 25    | ~$0.25 ✅        |
| 3      | 49    | ~$0.49           |
| 5      | 121   | ~$1.21           |

> No surprise charges — tile count is always `(2 × radius + 1)²`, known upfront.

***

### Use cases

- **Logistics & delivery** — route optimization based on real congestion data
- **Urban planning** — traffic pattern analysis by time of day / day of week
- **Real estate** — congestion scoring for property valuation
- **Retail analytics** — foot traffic and accessibility scoring near stores
- **Insurance** — road risk scoring by location and time

***

### Notes

- Data reflects Google Maps traffic patterns and is updated periodically by Google.
- Historical data (`seconds` parameter) is based on weekly recurring patterns, not archived snapshots.
- Higher zoom levels and larger radius values increase both cost and run time proportionally.

# Actor input Schema

## `lat` (type: `string`):

Latitude of the center point (e.g. -6.2193)

## `lon` (type: `string`):

Longitude of the center point (e.g. 106.8100)

## `zoom` (type: `integer`):

Map zoom level (10-20). 10-12 = city wide, 13-15 = district, 16-17 = street level (recommended), 18-20 = lane level.

## `radius` (type: `integer`):

Tile radius around center. Total tiles = (2r+1)^2. Cost = tiles x $0.010. radius 0=1 tile ($0.01), radius 1=9 tiles ($0.09), radius 2=25 tiles ($0.25), radius 3=49 tiles ($0.49), radius 5=121 tiles ($1.21).

## `seconds` (type: `integer`):

Seconds into the week for historical traffic (Sunday 00:00 UTC = 0). Use -1 for current live traffic.

## Actor input object example

```json
{
  "lat": "-6.219320790773214",
  "lon": "106.81002294222947",
  "zoom": 17,
  "radius": 2,
  "seconds": -1
}
```

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("romy/google-maps-traffic-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 = {}

# Run the Actor and wait for it to finish
run = client.actor("romy/google-maps-traffic-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 '{}' |
apify call romy/google-maps-traffic-scraper --silent --output-dataset

```

## MCP server setup

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

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Google Maps Traffic Scraper",
        "description": "Fetch real-time and historical traffic data from Google Maps as GeoJSON. Returns road-level speed levels, congestion status, and road segments for any coordinate and zoom level.",
        "version": "0.0",
        "x-build-id": "l7aHsgGkkQwCXShVC"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/romy~google-maps-traffic-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-romy-google-maps-traffic-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/romy~google-maps-traffic-scraper/runs": {
            "post": {
                "operationId": "runs-sync-romy-google-maps-traffic-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/romy~google-maps-traffic-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-romy-google-maps-traffic-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": [
                    "lat",
                    "lon",
                    "zoom",
                    "radius"
                ],
                "properties": {
                    "lat": {
                        "title": "Latitude",
                        "type": "string",
                        "description": "Latitude of the center point (e.g. -6.2193)",
                        "default": "-6.219320790773214"
                    },
                    "lon": {
                        "title": "Longitude",
                        "type": "string",
                        "description": "Longitude of the center point (e.g. 106.8100)",
                        "default": "106.81002294222947"
                    },
                    "zoom": {
                        "title": "Zoom Level",
                        "minimum": 10,
                        "maximum": 20,
                        "type": "integer",
                        "description": "Map zoom level (10-20). 10-12 = city wide, 13-15 = district, 16-17 = street level (recommended), 18-20 = lane level.",
                        "default": 17
                    },
                    "radius": {
                        "title": "Tile Radius",
                        "minimum": 0,
                        "maximum": 5,
                        "type": "integer",
                        "description": "Tile radius around center. Total tiles = (2r+1)^2. Cost = tiles x $0.010. radius 0=1 tile ($0.01), radius 1=9 tiles ($0.09), radius 2=25 tiles ($0.25), radius 3=49 tiles ($0.49), radius 5=121 tiles ($1.21).",
                        "default": 2
                    },
                    "seconds": {
                        "title": "Seconds into Week",
                        "type": "integer",
                        "description": "Seconds into the week for historical traffic (Sunday 00:00 UTC = 0). Use -1 for current live traffic.",
                        "default": -1
                    }
                }
            },
            "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
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
