---
title: "Geocodificação de Endereço"
description: "Conversão de endereço em coordenadas e de latitude e longitude em endereço (geocodificação direta e reversa). Retorna, na direta, latitude, longitude, endereço estruturado (rua, número, bairro, cidade, estado, CEP e país) e grau de confiança do resultado; na reversa, rua, bairro, cidade, estado, CEP, país e o endereço completo formatado."
lang: en
canonical: https://doc.apibrasil.io/apis/creditos/6ecd521d-b23d-4684-9add-c75b6d36df9f
markdown: https://doc.apibrasil.io/apis/creditos/6ecd521d-b23d-4684-9add-c75b6d36df9f.md
source: apibrasil-documentation
---

# Geocodificação de Endereço

> Conversão de endereço em coordenadas e de latitude e longitude em endereço (geocodificação direta e reversa). Retorna, na direta, latitude, longitude, endereço estruturado (rua, número, bairro, cidade, estado, CEP e país) e grau de confiança do resultado; na reversa, rua, bairro, cidade, estado, CEP, país e o endereço completo formatado.

- **Category:** Postal Codes & Utilities
- **Billing:** per query, with the Bearer Token only
- **Price:** R$0.09 per query
- **Limit:** 999,000 per month
- **Registration:** requires a CNPJ
- **Version:** v2
- **Published by:** APIBrasil
- **OpenAPI specification:** https://doc.apibrasil.io/apis/creditos/6ecd521d-b23d-4684-9add-c75b6d36df9f/openapi.json

## How to call

**Base address:** `https://gateway.apibrasil.io/api/v2`

Authentication: the `Authorization: Bearer <token>` header. Nothing else.

With `homolog: true` in the body, the gateway answers from a fixed base, with the real shape of the response, and does not charge. The CPF 00000000000 belongs to that base and to nobody: use it in tests, never in production.

## Endpoints (4 endpoints)

**Contents**

1. `POST /consulta/geolocation-credits/credits`
2. `POST /consulta/geolocation-credits/credits`
3. `POST /consulta/geolocation-credits/credits`
4. `POST /consulta/geolocation-credits/credits`

### 1. POST /consulta/geolocation-credits/credits

API Geolocation Crédito - Geocodificação reversa (homologação)

Converte coordenadas ("lat" e "lon") em endereço: rua, bairro, cidade, estado, CEP, país e o endereço completo formatado. Com "homolog": true a resposta traz um endereço fictício no mesmo formato da produção, sem consultar o fornecedor e sem cobrança.

- **Method:** `POST`
- **Address:** `https://gateway.apibrasil.io/api/v2/consulta/geolocation-credits/credits`
- **Route version:** v2

**Headers**

| Header | Value |
| --- | --- |
| `Content-Type` | `application/json` |
| `Authorization` | `Bearer $APIBRASIL_TOKEN` |

**Request body**

```json
{
  "tipo": "geocode",
  "homolog": true,
  "lat": -19.9322,
  "lon": -43.938
}
```

**In cURL**

```bash
curl -X POST "https://gateway.apibrasil.io/api/v2/consulta/geolocation-credits/credits" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $APIBRASIL_TOKEN" \
  -d '{"tipo":"geocode","homolog":true,"lat":-19.9322,"lon":-43.938}'
```

This endpoint accepts `homolog: true` in the body: the response comes back with valid data, `api_limit_for` equal to `homolog` and no charge.

**Sample response, from the catalog**

```json
{
  "user": {
    "first_name": "[omitido]",
    "email": "[omitido]",
    "cellphone": "[omitido]",
    "notification": "yes"
  },
  "balance": "1.000,000",
  "balance_before": "1.000,000",
  "tax": "0,000",
  "status_code": 200,
  "error": false,
  "message": "Dados validos em homologacao! Voce nao foi tarifado e a requisicao nao foi contabilizada.",
  "valor_consulta": 0,
  "api_limit_for": "homolog",
  "homolog": true,
  "data": {
    "address": {
      "city": "Cidade Exemplo",
      "city_district": "Distrito Exemplo",
      "country": "Brazil",
      "country_code": "br",
      "county": "Condado Exemplo",
      "municipality": "Municipio Exemplo",
      "neighbourhood": "Bairro Exemplo",
      "postcode": "30000-000",
      "region": "Regiao Exemplo",
      "road": "Rua Exemplo",
      "state": "Minas Gerais",
      "state_district": "Regiao Metropolitana"
    },
    "boundingbox": [
      "-19.9300",
      "-19.9200",
      "-43.9500",
      "-43.9400"
    ],
    "display_name": "Rua Exemplo, Bairro Exemplo, Cidade Exemplo, Minas Gerais, Brazil",
    "lat": "-19.9250",
    "licence_by": "https://apibrasil.io",
    "lon": "-43.9450",
    "osm_id": "123456789",
    "osm_type": "way",
    "place_id": "987654321"
  }
}
```

### 2. POST /consulta/geolocation-credits/credits

API Geolocation Crédito - Geocodificação reversa (produção)

Com "homolog": false as coordenadas são consultadas no fornecedor e a resposta traz o endereço real do ponto. A cobrança acontece só quando há resultado: coordenadas fora do intervalo (latitude de -90 a 90, longitude de -180 a 180) devolvem 400 sem cobrança.

- **Method:** `POST`
- **Address:** `https://gateway.apibrasil.io/api/v2/consulta/geolocation-credits/credits`
- **Route version:** v2

**Headers**

| Header | Value |
| --- | --- |
| `Content-Type` | `application/json` |
| `Authorization` | `Bearer $APIBRASIL_TOKEN` |

**Request body**

```json
{
  "tipo": "geocode",
  "homolog": false,
  "lat": -19.9322,
  "lon": -43.938
}
```

**In cURL**

```bash
curl -X POST "https://gateway.apibrasil.io/api/v2/consulta/geolocation-credits/credits" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $APIBRASIL_TOKEN" \
  -d '{"tipo":"geocode","homolog":false,"lat":-19.9322,"lon":-43.938}'
```

This endpoint accepts `homolog: true` in the body: the response comes back with valid data, `api_limit_for` equal to `homolog` and no charge.

**Sample response, from the catalog**

```json
{
  "user": {
    "first_name": "[omitido]",
    "email": "[omitido]",
    "cellphone": "[omitido]",
    "notification": "yes"
  },
  "balance": "999,910",
  "balance_before": "1.000,000",
  "tax": "0,090",
  "status_code": 200,
  "error": false,
  "message": "Dados validos! Voce foi tarifado em R$ 0,09.",
  "valor_consulta": 0.09,
  "api_limit_for": "credit",
  "homolog": false,
  "data": {
    "address": {
      "city": "Belo Horizonte",
      "city_district": "Regional Centro-Sul",
      "country": "Brazil",
      "country_code": "br",
      "county": "Região Metropolitana de Belo Horizonte",
      "municipality": "Região Geográfica Imediata de Belo Horizonte",
      "neighbourhood": null,
      "postcode": "30140-140",
      "region": "Southeast Region",
      "road": "Alameda Travessia",
      "state": "Minas Gerais",
      "state_district": "Região Geográfica Intermediária de Belo Horizonte"
    },
    "boundingbox": [
      "-19.9329564",
      "-19.9312096",
      "-43.9383392",
      "-43.9378336"
    ],
    "display_name": "Alameda Travessia, Savassi, Regional Centro-Sul, Belo Horizonte, Região Geográfica Imediata de Belo Horizonte, Região Metropolitana de Belo Horizonte, Região Geográfica Intermediária de Belo Horizonte, Minas Gerais, Southeast Region, 30140-140, Brazil",
    "lat": "-19.9321661",
    "licence_by": "https://apibrasil.io",
    "lon": "-43.9381273",
    "osm_id": "844448192",
    "osm_type": "way",
    "place_id": "12103719"
  }
}
```

### 3. POST /consulta/geolocation-credits/credits

API Geolocation Crédito - Geocodificação direta (homologação)

Converte um endereço em texto ("query") em coordenadas e endereço estruturado: latitude, longitude, rua, número, bairro, cidade, estado, CEP e país, com o grau de confiança do resultado. Com "homolog": true a resposta traz dados fictícios no mesmo formato da produção, sem consultar o fornecedor e sem cobrança.

- **Method:** `POST`
- **Address:** `https://gateway.apibrasil.io/api/v2/consulta/geolocation-credits/credits`
- **Route version:** v2

**Headers**

| Header | Value |
| --- | --- |
| `Content-Type` | `application/json` |
| `Authorization` | `Bearer $APIBRASIL_TOKEN` |

**Request body**

```json
{
  "tipo": "forward-geocoding",
  "homolog": true,
  "query": "Avenida Afonso Pena 1212, Belo Horizonte"
}
```

**In cURL**

```bash
curl -X POST "https://gateway.apibrasil.io/api/v2/consulta/geolocation-credits/credits" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $APIBRASIL_TOKEN" \
  -d '{"tipo":"forward-geocoding","homolog":true,"query":"Avenida Afonso Pena 1212, Belo Horizonte"}'
```

This endpoint accepts `homolog: true` in the body: the response comes back with valid data, `api_limit_for` equal to `homolog` and no charge.

**Sample response, from the catalog**

```json
{
  "user": {
    "first_name": "[omitido]",
    "email": "[omitido]",
    "cellphone": "[omitido]",
    "notification": "yes"
  },
  "balance": "1.000,000",
  "balance_before": "1.000,000",
  "tax": "0,000",
  "status_code": 200,
  "error": false,
  "message": "Dados validos em homologacao! Voce nao foi tarifado e a requisicao nao foi contabilizada.",
  "valor_consulta": 0,
  "api_limit_for": "homolog",
  "homolog": true,
  "data": {
    "administrative_area": "Area Exemplo",
    "confidence": 1,
    "continent": "South America",
    "country": "Brazil",
    "country_code": "BRA",
    "county": "Condado Exemplo",
    "label": "Rua Exemplo, 100, Cidade Exemplo, MG, Brasil",
    "latitude": -19.925,
    "licence_by": "https://apibrasil.io",
    "locality": "Cidade Exemplo",
    "longitude": -43.945,
    "name": "Rua Exemplo",
    "neighbourhood": "Centro",
    "number": "100",
    "postal_code": "30000000",
    "region": "Minas Gerais",
    "region_code": "MG",
    "street": "Rua Exemplo",
    "type": "address"
  }
}
```

### 4. POST /consulta/geolocation-credits/credits

API Geolocation Crédito - Geocodificação direta (produção)

Com "homolog": false o endereço é consultado no fornecedor e a resposta traz o melhor resultado encontrado. A cobrança acontece só quando há resultado: endereço que o fornecedor não encontra devolve 404 sem cobrança.

- **Method:** `POST`
- **Address:** `https://gateway.apibrasil.io/api/v2/consulta/geolocation-credits/credits`
- **Route version:** v2

**Headers**

| Header | Value |
| --- | --- |
| `Content-Type` | `application/json` |
| `Authorization` | `Bearer $APIBRASIL_TOKEN` |

**Request body**

```json
{
  "tipo": "forward-geocoding",
  "homolog": false,
  "query": "Avenida Afonso Pena 1212, Belo Horizonte"
}
```

**In cURL**

```bash
curl -X POST "https://gateway.apibrasil.io/api/v2/consulta/geolocation-credits/credits" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $APIBRASIL_TOKEN" \
  -d '{"tipo":"forward-geocoding","homolog":false,"query":"Avenida Afonso Pena 1212, Belo Horizonte"}'
```

This endpoint accepts `homolog: true` in the body: the response comes back with valid data, `api_limit_for` equal to `homolog` and no charge.

**Sample response, from the catalog**

```json
{
  "user": {
    "first_name": "[omitido]",
    "email": "[omitido]",
    "cellphone": "[omitido]",
    "notification": "yes"
  },
  "balance": "999,910",
  "balance_before": "1.000,000",
  "tax": "0,090",
  "status_code": 200,
  "error": false,
  "message": "Dados validos! Voce foi tarifado em R$ 0,09.",
  "valor_consulta": 0.09,
  "api_limit_for": "credit",
  "homolog": false,
  "data": {
    "administrative_area": "Belo Horizonte",
    "confidence": 1,
    "continent": "South America",
    "country": "Brazil",
    "country_code": "BRA",
    "county": "Belo Horizonte",
    "label": "Avenida Afonso Pena, Belo Horizonte, MG, Brazil",
    "latitude": -19.918997,
    "licence_by": "https://apibrasil.io",
    "locality": "Belo Horizonte",
    "longitude": -43.938577,
    "name": "Avenida Afonso Pena",
    "neighbourhood": null,
    "number": null,
    "postal_code": "30000-000",
    "region": "Minas Gerais",
    "region_code": "MG",
    "street": "Avenida Afonso Pena",
    "type": "street"
  }
}
```

In the sample responses, the fields of the account that generated the sample (`user.first_name`, `user.email`, `user.cellphone`) come out as `[omitido]`. The rest is what the catalog publishes.

## Pitfalls: what an integration gets wrong without warning

Established from the responses the catalog itself publishes. In every one of them the code works on the happy path and fails silently everywhere else:

1. **The error arrives in the BODY, with HTTP 200.**
   The response carries a boolean `error` field and a `message`. Checking only `response.ok` or the HTTP status lets a failure through as a success. ALWAYS check `error === false` before reading `data`.

2. **`balance`, `tax` and `extra_charges.total` are STRINGS in Brazilian format — and the format varies between APIs.**
   Values seen in the catalog: `"154,380"`, `"497,84"`, `"0,000"` and `"0.19"`. Comma in some, dot in another; three decimal places in some, two in another. In JavaScript, `parseFloat("154,380")` returns `154` and drops the cents with no error at all, and `Number("154,380")` returns `NaN`. Write a converter that handles both separators, and never use these fields in a financial decision without converting them.

3. **Every call costs money.**
   Blind retries multiply the bill. Never automatically repeat a 4xx: a bad parameter repeated is still bad, and still charged. Retry only timeouts and 5xx, with exponential backoff and a small attempt ceiling.

4. **HTTP 402 means insufficient balance, and retrying does not fix it.**
   It is the one status that needs a human — a top-up. Treat it as a terminal error with its own message, and do not lump it in with generic 4xx.

5. **`extra_charges` bills on top of the lookup price.**
   When the body asks for add-on services, the response lists each one with its price plus a `total` that is NOT included in the base amount. If you show cost to an end user, add both.

## See also

- OpenAPI specification: https://doc.apibrasil.io/apis/creditos/6ecd521d-b23d-4684-9add-c75b6d36df9f/openapi.json
- API catalog: [API catalog](https://doc.apibrasil.io/apis.md)
- Official SDKs: [Official SDKs](https://doc.apibrasil.io/sdks.md)
- Documentation index: https://doc.apibrasil.io/llms.txt
- HTML version of this page: https://doc.apibrasil.io/apis/creditos/6ecd521d-b23d-4684-9add-c75b6d36df9f
