Skip to main content

Geocoding endpoints

OpenWeatherMap Geocoding API 1.0 converts city names and postal codes into geographic coordinates (lat and lon) and converts coordinate pairs back into named localities.

For two-step coordinate resolution and caching recipes, see Use geographic coordinates.

Empty result behavior

The /geo/1.0/direct and /geo/1.0/reverse endpoints return HTTP 200 OK with an empty JSON array ([]) when no location matches your query, rather than HTTP 404 Not Found. Always verify that the array contains at least one element before reading index 0. By contrast, /geo/1.0/zip returns HTTP 404 Not Found with a JSON error object when a postal code is unrecognized.

Direct geocoding by place name​

Resolves a city or locality name into up to 5 candidate coordinate records.

GET https://api.openweathermap.org/geo/1.0/direct

Query parameters​

ParameterTypeRequiredDefaultDescription
qstringYes—Comma-separated city name, state code (US locations only), and ISO 3166-1 alpha-2 country code formatted as {city},{state},{country} (for example, London,GB or Portland,OR,US). URL-encode spaces and special characters.
limitnumberNo1Maximum number of matching locations returned in the response array, from 1 to 5.
appidstringYes—32-character hexadecimal API key. See Authentication.

Request examples​

curl --get "https://api.openweathermap.org/geo/1.0/direct" \
--data-urlencode "q=London" \
--data-urlencode "limit=2" \
--data-urlencode "appid=$OPENWEATHER_API_KEY"

Response​

Example 200 OK JSON array payload (local_names abbreviated for readability):

[
{
"name": "London",
"local_names": {
"ascii": "London",
"en": "London",
"es": "Londres",
"feature_name": "London",
"fr": "Londres"
},
"lat": 51.5073219,
"lon": -0.1276474,
"country": "GB",
"state": "England"
},
{
"name": "London",
"local_names": {
"en": "London",
"fr": "London"
},
"lat": 42.9832406,
"lon": -81.243372,
"country": "CA",
"state": "Ontario"
}
]

Response fields​

The root response is a JSON array (0–5 elements). Each element contains the following fields:

FieldTypeUnitDescription
namestring—Canonical name of the matched locality.
local_namesobject—Optional. Map of localized names and transliterations for the locality.
local_names.<lang>string—Optional. Locality name translated into ISO language code <lang> (such as en, es, or fr).
local_names.asciistring—Optional. ASCII transliteration of the locality name.
local_names.feature_namestring—Optional. Internal OpenWeatherMap geographic feature name.
latnumberDecimal degreesLatitude of the matched locality (-90 to 90).
lonnumberDecimal degreesLongitude of the matched locality (-180 to 180).
countrystring—ISO 3166-1 alpha-2 country code (for example, GB or CA).
statestring—Optional. State, province, or administrative region name when available.

Direct geocoding by postal or ZIP code​

Resolves a postal or ZIP code and country code into a single geographic coordinate object.

GET https://api.openweathermap.org/geo/1.0/zip

Query parameters​

ParameterTypeRequiredDefaultDescription
zipstringYes—Postal or ZIP code and ISO 3166-1 alpha-2 country code formatted as {zip code},{country code} (for example, E14,GB or 94040,US). Defaults to US when the country code is omitted.
appidstringYes—32-character hexadecimal API key. See Authentication.

Request example​

curl --get "https://api.openweathermap.org/geo/1.0/zip" \
--data-urlencode "zip=E14,GB" \
--data-urlencode "appid=$OPENWEATHER_API_KEY"

Response​

Example 200 OK JSON object payload:

{
"zip": "E14",
"name": "London",
"lat": 51.5096,
"lon": -0.0156,
"country": "GB"
}

Response fields​

FieldTypeUnitDescription
zipstring—Matched postal or ZIP code.
namestring—Locality or district name associated with the postal code.
latnumberDecimal degreesLatitude of the postal area centroid (-90 to 90).
lonnumberDecimal degreesLongitude of the postal area centroid (-180 to 180).
countrystring—ISO 3166-1 alpha-2 country code (for example, GB or US).

Reverse geocoding by coordinates​

Resolves a geographic coordinate pair (lat and lon) into up to 5 nearby named localities.

GET https://api.openweathermap.org/geo/1.0/reverse

Query parameters​

ParameterTypeRequiredDefaultDescription
latnumberYes—Latitude in decimal degrees, ranging from -90 to 90 (positive for north, negative for south).
lonnumberYes—Longitude in decimal degrees, ranging from -180 to 180 (positive for east, negative for west).
limitnumberNo1Maximum number of nearby localities returned in the response array, from 1 to 5.
appidstringYes—32-character hexadecimal API key. See Authentication.

Request example​

curl --get "https://api.openweathermap.org/geo/1.0/reverse" \
--data-urlencode "lat=51.5098" \
--data-urlencode "lon=-0.1180" \
--data-urlencode "limit=1" \
--data-urlencode "appid=$OPENWEATHER_API_KEY"

Response​

Example 200 OK JSON array payload:

[
{
"name": "City of Westminster",
"local_names": {
"ascii": "City of Westminster",
"en": "City of Westminster",
"feature_name": "City of Westminster",
"fr": "Cité de Westminster"
},
"lat": 51.4973206,
"lon": -0.137149,
"country": "GB",
"state": "England"
}
]

Response fields​

Returns a JSON array (0–5 elements) using the identical element schema documented under Direct geocoding by place name (name, local_names, lat, lon, country, and state).

Status codes​

Status codeMeaningDescription
200OKRequest succeeded. Returns a JSON array on /direct and /reverse (including [] when no location matches) or a JSON object on /zip.
400Bad RequestMissing required query parameter ("Nothing to geocode") or out-of-range coordinates (cod is "400").
401UnauthorizedMissing, invalid, inactive, or unauthorized appid (cod is 401).
404Not FoundPostal code not found on /geo/1.0/zip (cod is "404").
429Too Many RequestsAccount rate limit exceeded (cod is 429).
5xxServer ErrorUpstream OpenWeatherMap server or gateway error.

For full error payload schemas and cod type behavior, see Error codes.