NewConnect Claude, Cursor, ChatGPT, and other AI agents to API Ninjas via our MCP server

Geocoding API

The Geocoding API enables you to convert any city from any country to latitude and longitude coordinates. For reverse-geocoding, check out our Reverse Geocoding API.

(4.5)

From 2,473 users

700+

Applications using this API

API Status

Online - All Systems Operational

API Response Times

Average
P50
P75
P90
P95
192ms226ms251ms443ms881ms

Didn't find what you were looking for? Suggest an improvement


/v1/geocoding GET

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:

  • city  required

    City name.

  • state  optional

    US state (for United States cities only).

  • country  optional

    Country name, 2-letter ISO country code, or 3-letter ISO country code.

  • zipcode  optional

    5-digit zipcode (for United States cities only).

Headers

  • X-Api-Key  required

    API Key associated with your account.

Response

A JSON array of objects, each containing the following fields, or an error if the request is unsuccessful.

  • name

    The name of the city.

  • latitude

    Latitude coordinate of the city.

  • longitude

    Longitude coordinate of the city.

  • country

    2-letter ISO 3166 alpha-2 country code.

Sample Request Live Demo!

city
state
country
zipcode

Try this API endpoint with all available parameters in our API playground

https://api.api-ninjas.com/v1/geocoding?city=London&country=GB

Headers

X-Api-KeyLog in or sign up to get your API Key

Sample Response

JSON

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.