# Reverse Geocoder – Lat/Long to Country, State, City & Time Zone (`gazidev/reverse-geocoder`) Actor

Bulk offline reverse geocoding: turn latitude/longitude into country (ISO codes), state/province, nearest city or town, IANA time zone and UTC offset. Lists, CSV/JSON files or Apify datasets (e.g. Google Maps results). No API key. City level, no street addresses. $0.20 per 1,000.

- **URL**: https://apify.com/gazidev/reverse-geocoder.md
- **Developed by:** [Cemal Atakli](https://apify.com/gazidev) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.20 / 1,000 coordinate resolveds

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?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## 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.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Reverse Geocoder – Bulk Latitude/Longitude to Country, State, City & Time Zone

Turn **latitude/longitude coordinates into country, state/province, nearest city or town and time zone** – in bulk, fully offline. Paste a list, point it at a CSV/JSON file, or pick an Apify dataset (for example the results of a Google Maps scraper) and get one clean row per point.

- **Country**: ISO 3166-1 alpha-2 and alpha-3 code, English name, continent, EU member flag
- **State / province** (first-level division): local and English name, ISO 3166-2 code (e.g. `US-NY`, `TR-34`), type
- **Nearest populated place** (towns with 15,000+ inhabitants): name, region, country, population, its coordinates and the distance in km
- **Time zone**: IANA name (`Europe/Paris`), current UTC offset (`+01:00`), offset in minutes, daylight-saving flag
- **`inOcean`** flag for points at sea

No Google, no Nominatim, no API key, no rate limits: all data is bundled in the Actor, so 100,000 points take well under a minute.

> **City level only – no street addresses.** This Actor tells you *which country, state and nearby town* a point is in. It does not return house numbers, streets or postcodes. If you need street addresses, use a street-level geocoding service.

### What this listing does that our other geo Actors do not

| Actor | Direction | Coverage |
|---|---|---|
| **Reverse Geocoder** (this one) | coordinates → country / state / town / time zone | worldwide, offline, bulk |
| [Address Geocoder](https://apify.com/gazidev/address-geocoder) | address → coordinates (and US census geographies) | US and France official geocoders |
| [Image Metadata Extractor](https://apify.com/gazidev/image-metadata-extractor) | photo EXIF GPS → nearest city, plus camera data | photos only |
| [Bulk IP Lookup](https://apify.com/gazidev/bulk-ip-lookup) | IP address → network, country | IPs, not coordinates |

### Use cases

- **Enrich scraped places**: add ISO country, state code and time zone to Google Maps / OpenStreetMap / store-locator results before loading them into a CRM.
- **Lead routing by region or time zone**: assign leads to sales territories, schedule calls in the prospect's local time.
- **Clean location data**: find rows with swapped or impossible coordinates, `0,0` placeholders and points in the ocean.
- **Analytics**: aggregate GPS events, IoT devices, delivery stops or photo locations by country and state.
- **Compliance**: flag EU locations (`isEU`) for GDPR-related processing.

### Input

Use any combination of these sources:

| Field | What it is |
|---|---|
| `coordinates` | List of `latitude, longitude` lines. Also accepted: `48.8584 N, 2.2945 E`, degrees-minutes-seconds `48°51'30"N 2°17'40"E`, `lat;lon` (decimal commas OK), Google Maps links (`…/@41.89,12.49,17z`, `!3d…!4d…`). |
| `datasetId` | An Apify dataset (picker). Coordinates are detected automatically in `location.lat` / `location.lng` (Google Maps scrapers), `lat` / `lng` / `lon`, `latitude` / `longitude`, GeoJSON `Point` geometry or a text field like `coordinates`. |
| `fileUrl` | Public CSV (comma, semicolon, tab or pipe), JSON array or JSON Lines file, up to 500 MB. Same column detection. |
| `latitudeField` / `longitudeField` / `coordinatesField` | Optional explicit field names (dots for nested fields, e.g. `location.lat`). |
| `keepFields` | Fields copied from each item into `source` so you can join results back (default: `title`, `name`, `id`, `placeId`, `url`). |
| `skipDuplicates` | Identical points are resolved and charged once (default on). |
| `zeroIsMissing` | `0, 0` is treated as a missing value (default on). |
| `maxPlaceDistanceKm` | Nearest place is reported only within this distance (default 150 km). |
| `coastToleranceKm` | Points just off the coastline (beach, pier, harbour) still get the country/state within this distance (default 3 km). |
| `onlyResolved`, `maxItems` | Leave out free rows; cap the number of inputs. |

Example:

```json
{
  "datasetId": "YOUR_GOOGLE_MAPS_RUN_DATASET_ID",
  "keepFields": ["title", "placeId", "address"]
}
```

### Output

One row per input point (duplicates skipped), in input order (`inputIndex`):

```json
{
  "inputIndex": 0,
  "input": "48.8584, 2.2945",
  "latitude": 48.8584,
  "longitude": 2.2945,
  "result": "resolved",
  "countryCode": "FR",
  "countryCode3": "FRA",
  "countryName": "France",
  "continent": "Europe",
  "isEU": true,
  "inOcean": false,
  "countryMatch": "inside",
  "stateName": "Paris",
  "stateNameEn": "Paris",
  "stateCode": "FR-75",
  "stateType": "Metropolitan department",
  "nearestPlace": "Paris 16 Passy",
  "nearestPlaceRegion": "Île-de-France",
  "nearestPlaceCountryCode": "FR",
  "nearestPlacePopulation": 159386,
  "nearestPlaceLatitude": 48.8637,
  "nearestPlaceLongitude": 2.2769,
  "distanceKm": 1.42,
  "timezone": "Europe/Paris",
  "utcOffset": "+01:00",
  "utcOffsetMinutes": 60,
  "isDst": false,
  "source": null,
  "error": null
}
```

`result` is `resolved` (charged), `noMatch` (open ocean, no country or town nearby – free) or `invalid` (unreadable or out-of-range input – free, with the reason in `error`). The run summary (counts per country, attribution) is in the `OUTPUT` record of the key-value store. Export as JSON, CSV, Excel or via API.

### Pricing

Pay per event – you only pay for points that were resolved:

| Event | Price |
|---|---|
| Coordinate resolved (country or nearest place found) | **$0.0002** ($0.20 per 1,000) |
| Actor start | $0.00005 |

Free: invalid coordinates, `0,0` placeholders, duplicates, and open-ocean points with nothing nearby. Set a maximum total charge on the run and the Actor stops cleanly when it is reached (the summary shows how many points were not processed).

Comparison (Apify Store, November 2026): Nominatim/OSM-based actors charge about $0.001–0.002 per point plus start fees and depend on public servers whose usage policy forbids bulk use; Google-based scrapers charge ~$0.0001 but return street addresses scraped from Google. This Actor is the offline, ToS-clean option for country/state/town/time-zone enrichment.

### Accuracy and limits (please read)

- **City level, no street addresses, no postcodes.**
- **Nearest place = nearest town with 15,000+ inhabitants** (GeoNames cities15000). In rural areas it can be 20–40 km away (or more in deserts and the Arctic); always check `distanceKm`. It is the nearest *point*, not the municipality that contains the coordinate, and can lie across a border (compare `nearestPlaceCountryCode` with `countryCode`).
- **Country and state come from polygons** (Natural Earth 1:10m, simplified to ~300 m), so they are usually right even near a border, but points within a few hundred metres of a border or coastline may be assigned to the neighbour. `countryMatch: coastal` marks points matched by the coast tolerance.
- **"State" means the first-level division as mapped by Natural Earth.** This is states/provinces in most countries, but e.g. departments in France and counties/unitary authorities in the UK. Some small divisions have no ISO 3166-2 code (`stateCode: null`).
- **Disputed areas** follow Natural Earth's de-facto view and may not match your preferred policy.
- **Time zone offsets** are for the moment of the run (DST included). Ocean points get nautical `Etc/GMT±N` zones.

### FAQ

**Can it handle millions of points?** Yes. Inputs are streamed in batches of 1,000; memory stays at ~250 MB. Very large runs are limited mostly by dataset write speed.

**Do I need an API key?** No. Nothing is sent to any geocoding service. The only network request is downloading your `fileUrl`, if you use one (private-network addresses are refused).

**My dataset uses other field names.** Set `latitudeField` and `longitudeField` (e.g. `geo.latitude`), or `coordinatesField` for a single `"lat, lon"` text field.

**Why is a point flagged `invalid`?** Latitude outside -90..90 (often swapped with longitude), longitude outside -180..180, `0,0`, or text that does not contain two coordinates. These rows are free.

### Use with AI agents / Apify MCP

Through the [Apify MCP server](https://mcp.apify.com) an AI agent can call `gazidev/reverse-geocoder` with `{"coordinates": ["51.5007, -0.1246"]}` and read back country, state, town and time zone – useful for "what time is it there?", "which country is this GPS point in?" or enriching a scraped dataset inside an agent workflow.

### Data sources and attribution

- Places: [GeoNames](https://www.geonames.org) cities15000, licensed CC BY 4.0.
- Country and state borders: [Natural Earth](https://www.naturalearthdata.com) admin-0 / admin-1, public domain.
- Time zones: [timezonefinder](https://github.com/jannikmi/timezonefinder) (MIT), boundary data from [timezone-boundary-builder](https://github.com/evansiroky/timezone-boundary-builder) (ODbL).

The data is bundled at build time; GeoNames and OSM servers are never contacted by this Actor.

# Actor input Schema

## `coordinates` (type: `array`):

One point per line as `latitude, longitude` (e.g. `48.8584, 2.2945`). Also accepted: `48.8584 N, 2.2945 E`, degrees-minutes-seconds (`48°51'30"N 2°17'40"E`), `lat;lon`, and Google Maps links (`.../@48.85,2.29,15z`). Invalid lines get a free error row. The example list is ignored when you also pick a dataset or file.

## `datasetId` (type: `string`):

Pick a dataset from an earlier run (for example a Google Maps scraper run). Latitude/longitude are found automatically in `location.lat`/`location.lng`, `lat`/`lng`/`lon`, `latitude`/`longitude`, GeoJSON points or a `coordinates` text field. Set the field names below if yours differ.

## `fileUrl` (type: `string`):

Public URL of a CSV (comma, semicolon, tab or pipe separated, with a header row), JSON array or JSON Lines file. Columns are detected like dataset fields. Max 500 MB. Private-network addresses are refused.

## `latitudeField` (type: `string`):

Optional. Column or field path for latitude in the dataset/file, e.g. `lat` or `location.lat` (dots for nested fields). Set together with 'Longitude field'.

## `longitudeField` (type: `string`):

Optional. Column or field path for longitude, e.g. `lng` or `location.lng`.

## `coordinatesField` (type: `string`):

Optional. A single field holding both values, e.g. `gps` with text `48.85, 2.29`, a `{lat, lng}` object or a Google Maps link. Overrides the two fields above.

## `keepFields` (type: `array`):

Fields of each dataset/file item copied into `source` in the output, so you can join the result back (dots for nested fields). Missing fields are ignored.

## `skipDuplicates` (type: `boolean`):

Identical points (to 6 decimals) are resolved and charged once; later copies get no row. Turn off to get one row per input row (each one charged).

## `zeroIsMissing` (type: `boolean`):

`0, 0` ("Null Island", in the Atlantic) is nearly always a placeholder for a missing location. When on, it gets a free 'invalid' row.

## `maxPlaceDistanceKm` (type: `integer`):

The nearest populated place is only reported if it is within this distance. Places are towns with 15,000+ inhabitants, so remote points can be far from one.

## `coastToleranceKm` (type: `integer`):

Points just off the (simplified) coastline, e.g. on a beach, pier or harbour, are matched to the nearest country/state within this distance (`countryMatch: coastal`). 0 = strict polygons only.

## `onlyResolved` (type: `boolean`):

Leave out the free rows for invalid inputs and open-ocean points with no match.

## `maxItems` (type: `integer`):

Optional cap on how many input rows are read (all sources together).

## Actor input object example

```json
{
  "coordinates": [
    "48.8584, 2.2945",
    "40.7580, -73.9855",
    "35.6586, 139.7454",
    "-33.8568, 151.2153",
    "41.0082, 28.9784",
    "-1.2921, 36.8219",
    "30.0, -40.0",
    "not a coordinate"
  ],
  "keepFields": [
    "title",
    "name",
    "id",
    "placeId",
    "url"
  ],
  "skipDuplicates": true,
  "zeroIsMissing": true,
  "maxPlaceDistanceKm": 150,
  "coastToleranceKm": 3,
  "onlyResolved": false
}
```

# Actor output Schema

## `overview` (type: `string`):

No description

## `details` (type: `string`):

No description

## `summary` (type: `string`):

No description

## `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 = {
    "coordinates": [
        "48.8584, 2.2945",
        "40.7580, -73.9855",
        "35.6586, 139.7454",
        "-33.8568, 151.2153",
        "41.0082, 28.9784",
        "-1.2921, 36.8219",
        "30.0, -40.0",
        "not a coordinate"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("gazidev/reverse-geocoder").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 = { "coordinates": [
        "48.8584, 2.2945",
        "40.7580, -73.9855",
        "35.6586, 139.7454",
        "-33.8568, 151.2153",
        "41.0082, 28.9784",
        "-1.2921, 36.8219",
        "30.0, -40.0",
        "not a coordinate",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("gazidev/reverse-geocoder").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 '{
  "coordinates": [
    "48.8584, 2.2945",
    "40.7580, -73.9855",
    "35.6586, 139.7454",
    "-33.8568, 151.2153",
    "41.0082, 28.9784",
    "-1.2921, 36.8219",
    "30.0, -40.0",
    "not a coordinate"
  ]
}' |
apify call gazidev/reverse-geocoder --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,gazidev/reverse-geocoder"
        }
    }
}
```

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/kSETjLmu5dxMA66oZ/builds/ZgqCyCBTmwN628XdE/openapi.json
