Geocoding & Reverse Geocoding API
The Geocoding API converts between place names and geographic coordinates in both directions. It resolves cities, towns, and US ZIP codes — not street addresses.
Every lookup returns the administrative hierarchy with ISO 3166-2 codes, IANA timezone, population and elevation, and country context such as currency, calling code, languages and EU/EEA membership — plus alternative coordinate formats including Plus Codes and geohash. Premium subscribers additionally receive climate zone, degree of urbanisation and the nearest airport.
Available endpoints:
- /v1/geocoding - Convert a city, state, or US ZIP code to latitude and longitude coordinates
- /v1/reversegeocoding - Convert latitude and longitude coordinates to the nearest city, state, and country
From 2,473 users
Applications using this API
API Status
API Response Times
Average | P50 | P75 | P90 | P95 |
|---|---|---|---|---|
| 194ms | 239ms | 287ms | 671ms | 873ms |
Didn't find what you were looking for? Suggest an improvement
https://api.api-ninjas.com/v1/geocoding
Get current city coordinates by city and country name.
Parameters
At least one of the following parameters must be set:
cityrequiredCity name.
stateoptionalUS state (for United States cities only).
countryoptionalCountry name, 2-letter ISO country code, or 3-letter ISO country code.
zipcodeoptional5-digit zipcode (for United States cities only).
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Response
A JSON array of objects, each containing the following fields, or an error if the request is unsuccessful.
Core
nameThe name of the matched place.
latitudeLatitude coordinate in WGS 84 decimal degrees.
longitudeLongitude coordinate in WGS 84 decimal degrees.
country2-letter ISO 3166-1 alpha-2 country code.
stateState, province or region of the place. Not returned for all locations.
Place
admin1_nameFirst-level administrative division — state, province or region (e.g.
England).admin1_isoISO 3166-2 code for that division (e.g.
GB-ENG).admin2_nameSecond-level division — county or equivalent. Available for about 86% of places worldwide; sparse in Germany and Russia.
timezoneIANA timezone name (e.g.
Europe/London).populationPopulation of the matched place.
elevation_mElevation of the matched place in metres. Surveyed where available, otherwise the SRTM DEM value for the settlement — not a per-coordinate sample.
Country
country_nameFull country name.
iso3ISO 3166-1 alpha-3 country code.
iso_numericISO 3166-1 numeric country code.
capitalCapital city.
continentTwo-letter continent code.
regionUN M49 region name.
subregionUN M49 sub-region name.
currencyISO 4217 currency code.
currency_nameCurrency name.
calling_codeInternational dialling prefix (e.g.
+44).languagesComma-separated BCP-47 language tags.
tldCountry-code top-level domain.
driving_sideleftorright.is_euWhether the country is an EU member state.
is_eeaWhether the country is in the European Economic Area.
Coordinate formats
plus_codeOpen Location Code (Plus Code) for the coordinate.
geohash9-character geohash.
dmsDegrees/minutes/seconds strings for latitude and longitude.
mercatorWeb Mercator (EPSG:3857)
xandyin metres.antipodeThe point diametrically opposite on the globe.
hemisphereNorth/south and east/west indicators.
qibla_degreesBearing to the Kaaba in Mecca, degrees clockwise from true north.
osmOpenStreetMap view, edit and note URLs.
sunSunrise, sunset, solar noon, the three twilight bands and day length for today in UTC. Sub-values are
nullabove the polar circles, wherepolar_dayandpolar_nightsay why.
Environment
climate_zonepremium onlyKöppen-Geiger climate code (e.g.
Cfb).climate_zone_namepremium onlyHuman-readable climate classification.
urbanisationpremium onlyGHSL degree-of-urbanisation class, from
URBAN_CENTREthroughVERY_LOW_DENSITY_RURALtoWATER.urbanisation_namepremium onlyHuman-readable urbanisation class.
is_landpremium onlyWhether the coordinate is on land. Inland water counts as not land.
nearest_airportpremium onlyNearest IATA-coded airport, with distance and bearing.
United States only
countypremium onlyUS county. Returned only from an authoritative match —
nullrather than a guess.zip_codepremium onlyUS ZIP code of the matched place. See
zip_code_accuracy; this is not a point-in-polygon result.zip_code_accuracypremium onlyHow
zip_codewas derived:exact,place_centroidornearest.area_codespremium onlyUS telephone area codes serving the location.
Sample Request Live Demo!
Try our APIs in the API playground
Sign up for a free API key to get started — no credit card required.
https://api.api-ninjas.com/v1/geocoding?city=London&country=GBHeaders
X-Api-KeyLog in or sign up to get your API KeySample Response
Code Examples
1
2
curl -X GET "https://api.api-ninjas.com/v1/geocoding?city=London&country=GB" \
-H "X-Api-Key: YOUR_API_KEY"If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.
https://api.api-ninjas.com/v1/reversegeocoding
Returns a list of cities that contain a given latitude and longitude.
Parameters
latrequiredLatitude coordinate.
lonrequiredLongitude coordinate.
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Response
A JSON array of location objects, each containing the following fields, or an error if the request is unsuccessful.
Core
nameThe name of the nearest matched place.
country2-letter ISO 3166-1 alpha-2 country code.
stateState, province or region. Not returned for all locations.
Place
admin1_nameFirst-level administrative division — state, province or region (e.g.
England).admin1_isoISO 3166-2 code for that division (e.g.
GB-ENG).admin2_nameSecond-level division — county or equivalent. Available for about 86% of places worldwide; sparse in Germany and Russia.
timezoneIANA timezone name (e.g.
Europe/London).populationPopulation of the matched place.
elevation_mElevation of the matched place in metres. Surveyed where available, otherwise the SRTM DEM value for the settlement — not a per-coordinate sample.
Country
country_nameFull country name.
iso3ISO 3166-1 alpha-3 country code.
iso_numericISO 3166-1 numeric country code.
capitalCapital city.
continentTwo-letter continent code.
regionUN M49 region name.
subregionUN M49 sub-region name.
currencyISO 4217 currency code.
currency_nameCurrency name.
calling_codeInternational dialling prefix (e.g.
+44).languagesComma-separated BCP-47 language tags.
tldCountry-code top-level domain.
driving_sideleftorright.is_euWhether the country is an EU member state.
is_eeaWhether the country is in the European Economic Area.
Coordinate formats
plus_codeOpen Location Code (Plus Code) for the coordinate.
geohash9-character geohash.
dmsDegrees/minutes/seconds strings for latitude and longitude.
mercatorWeb Mercator (EPSG:3857)
xandyin metres.antipodeThe point diametrically opposite on the globe.
hemisphereNorth/south and east/west indicators.
qibla_degreesBearing to the Kaaba in Mecca, degrees clockwise from true north.
osmOpenStreetMap view, edit and note URLs.
sunSunrise, sunset, solar noon, the three twilight bands and day length for today in UTC. Sub-values are
nullabove the polar circles, wherepolar_dayandpolar_nightsay why.
Environment
climate_zonepremium onlyKöppen-Geiger climate code (e.g.
Cfb).climate_zone_namepremium onlyHuman-readable climate classification.
urbanisationpremium onlyGHSL degree-of-urbanisation class, from
URBAN_CENTREthroughVERY_LOW_DENSITY_RURALtoWATER.urbanisation_namepremium onlyHuman-readable urbanisation class.
is_landpremium onlyWhether the coordinate is on land. Inland water counts as not land.
nearest_airportpremium onlyNearest IATA-coded airport, with distance and bearing.
United States only
countypremium onlyUS county. Returned only from an authoritative match —
nullrather than a guess.zip_codepremium onlyUS ZIP code of the matched place. See
zip_code_accuracy; this is not a point-in-polygon result.zip_code_accuracypremium onlyHow
zip_codewas derived:exact,place_centroidornearest.area_codespremium onlyUS telephone area codes serving the location.
Sample Request Live Demo!
Try our APIs in the API playground
Sign up for a free API key to get started — no credit card required.
https://api.api-ninjas.com/v1/reversegeocoding?lat=51.509865&lon=-0.118092Headers
X-Api-KeyLog in or sign up to get your API KeySample Response
Code Examples
1
2
curl -X GET "https://api.api-ninjas.com/v1/reversegeocoding?lat=40.7128&lon=-74.0060" \
-H "X-Api-Key: YOUR_API_KEY"If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.
Frequently Asked Questions
Can I use the Geocoding API for commercial purposes?
Yes, but you must have a premium subscription. Commercial use of the Geocoding API is not permitted on the free tier. See our pricing page to choose a plan that fits your needs.How do I get an API key and start using the Geocoding API?
Sign up for a free account to instantly get your API key, then pass it in theX-Api-Keyheader on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.What happens if I exceed my quota for the month?
Your API requests will simply be denied once you hit your monthly quota — you will never be charged more than the plan you signed up for. To increase your quota, you can upgrade your plan any time on our pricing page.What happens if a request to the Geocoding API fails?
The API responds with a standard HTTP status code and a JSON error message describing the problem. See our error codes reference for the full list of codes and how to resolve each one, or contact support if you need help.What are some use cases for the Reverse Geocoding API?
It is ideal for translating raw GPS or devicelat/loncoordinates into human-readable place names for ride-sharing apps, delivery tracking, store locators, and analytics dashboards. For the opposite direction (turning a place name into coordinates), use the Geocoding API.How do I query a location by coordinates?
Send a GET request to the/v1/reversegeocodingendpoint with the requiredlatandlonquery parameters, for example?lat=40.7128&lon=-74.0060. See the pricing page for request limits per plan.What does the Reverse Geocoding API response include?
It returns a JSON array of location objects, each with aname(city, town, or area), acountryfield as a 2-letter ISO 3166 alpha-2 code, and astatefield for the province or administrative region. If you also need detailed city statistics like population, pair it with the City API.Can I get coordinates from an IP address or find the time zone for a location?
The Reverse Geocoding API only acceptslatandloncoordinates, so to derive a location from a visitor's IP first use the IP Lookup API, and to find the time zone for a set of coordinates use the Timezone API.How do I disambiguate a city when the same name exists in multiple countries?
Pass thecountryparameter alongsidecity— it accepts a country name, a 2-letter ISO code, or a 3-letter ISO code (for examplecountry=GBfor London). For United States cities you can further narrow results with thestateparameter or a 5-digitzipcode. Browse related location tools in the API catalog.What fields does the Geocoding response include?
It returns a JSON array of objects, each containing the cityname, itslatitudeandlongitudecoordinates, and the 2-letter ISO 3166 alpha-2countrycode. Failed requests return an error instead, as described in our error codes documentation.How do I convert coordinates back into a city name?
The Geocoding endpoint only converts forward, from a city to itslatitudeandlongitude; to go the other direction and resolve coordinates into a location, use our Reverse Geocoding endpoint instead.Can I get more detail about a city beyond its coordinates?
This endpoint returns onlyname,latitude,longitude, andcountry; for richer data such as population or region, use the City API, or look up the local time at those coordinates with the Timezone API.