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.

/v1/geocoding GET

https://api.api-ninjas.com/v1/geocoding

Get current city coordinates by city and country name.


Parameters

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

Headers

  • X-Api-Key  required

    API Key associated with your account.

Sample Request Live Demo!

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

Sample Response

JSON
1 2 3 4 5 6 7 8 [ { "name": "London", "latitude": 51.5085, "longitude": -0.1257, "country": "GB" } ]

Code Examples

1 2 3 4 5 6 7 8 9 import requests city = 'london' api_url = 'https://api.api-ninjas.com/v1/geocoding?city={}'.format(city) response = requests.get(api_url + city, headers={'X-Api-Key': 'YOUR_API_KEY'}) if response.status_code == requests.codes.ok: print(response.text) else: print("Error:", response.status_code, response.text)

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.