# 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:** 54 total users, 6 monthly users, 99.6% runs succeeded, 2 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.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/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 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.001   | 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.001          |
| 1      | 9     | ~$0.009          |
| 2      | 25    | ~$0.025 ✅       |
| 3      | 49    | ~$0.049          |
| 5      | 121   | ~$0.121          |

> 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
}
```

# Actor output Schema

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

No description

# 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(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 '{}' |
apify call romy/google-maps-traffic-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,romy/google-maps-traffic-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/qlLfzCYcQfFM9S5n1/builds/QBwwzgQJiBtAqNQmI/openapi.json
