Skip to content

Geocoding ​

AstroAPI provides a geocoding endpoint to search for places and get their coordinates. This is useful for converting location names to latitude/longitude values required by calculation endpoints.

Search for Places ​

Search for cities, towns, and other places by name:

bash
curl -X GET "https://api.astroapi.cloud/api/geocoding/search?q=Amsterdam" \
  -H "X-Api-Key: your-api-key"

Query Parameters ​

ParameterRequiredDescription
qYesSearch query (2-100 characters)
limitNoMaximum results (1-10, default: 5)
langNoLanguage code (default: "en")

Response ​

json
{
  "data": [
    {
      "id": "node_123456",
      "name": "Amsterdam",
      "displayName": "Amsterdam, North Holland, Netherlands",
      "latitude": 52.3676,
      "longitude": 4.9041,
      "country": "Netherlands",
      "countryCode": "NL",
      "state": "North Holland",
      "city": "Amsterdam"
    }
  ]
}

Response Fields ​

FieldDescription
idUnique identifier (OpenStreetMap ID)
namePrimary place name
displayNameFull formatted name with region and country
latitudeLatitude coordinate
longitudeLongitude coordinate
countryCountry name
countryCodeISO 2-letter country code
stateState/province/region name
cityCity name (if applicable)

Code Examples ​

JavaScript ​

javascript
async function searchPlace(query) {
  const response = await fetch(
    `https://api.astroapi.cloud/api/geocoding/search?q=${encodeURIComponent(query)}`,
    {
      headers: {
        "X-Api-Key": "your-api-key"
      }
    }
  );
  const { data } = await response.json();
  return data;
}

// Usage
const results = await searchPlace("London");
const { latitude, longitude } = results[0];
console.log(`London: ${latitude}, ${longitude}`);

Python ​

python
import requests

def search_place(query):
    response = requests.get(
        "https://api.astroapi.cloud/api/geocoding/search",
        params={"q": query},
        headers={"X-Api-Key": "your-api-key"}
    )
    return response.json()["data"]

# Usage
results = search_place("Paris")
place = results[0]
print(f"Paris: {place['latitude']}, {place['longitude']}")

Using with Natal Chart ​

Combine geocoding with natal chart calculation:

javascript
// Step 1: Search for birthplace
const places = await searchPlace("New York");
const birthplace = places[0];

// Step 2: Calculate natal chart
const response = await fetch("https://api.astroapi.cloud/api/calc/natal", {
  method: "POST",
  headers: {
    "X-Api-Key": "your-api-key",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    datetime: "1990-06-15T14:30:00",
    latitude: birthplace.latitude,
    longitude: birthplace.longitude,
    timezone: "America/New_York"
  })
});

Language Support ​

The geocoding endpoint supports multiple languages for place names. Use the lang parameter:

bash
# German
curl "https://api.astroapi.cloud/api/geocoding/search?q=Munich&lang=de"

# French
curl "https://api.astroapi.cloud/api/geocoding/search?q=Munich&lang=fr"

Supported language codes include: en, de, fr, es, it, nl, pt, ru, ja, zh, and more.

Caching ​

Geocoding results are cached for 24 hours to improve performance. The same search query will return cached results without hitting the upstream geocoding service.

Rate Limits ​

Geocoding requests count towards your API rate limits. See Rate Limits for details.

AstroAPI Documentation