DEV Community

Cover image for I Built a Global Location Data API with 32.5M+ Cities — Here's How
Bosco Edwin
Bosco Edwin

Posted on • Edited on

I Built a Global Location Data API with 32.5M+ Cities — Here's How

Every developer has hit this wall. You're building an app. You need a city search dropdown, or postal code validation, or timezone detection. Simple stuff. You look at Google Maps Platform pricing. You close the tab. That's why I built LocalityAPI.

The Problem With Existing Solutions

Google Maps Platform is comprehensive but expensive. $5 per 1,000 Place Autocomplete requests. $17 per 1,000 Geocoding requests. For a startup doing 100,000 requests per month that's $500-1,700 monthly just for location data. Before you've made a dollar.

Free alternatives exist but come with serious tradeoffs. GeoNames has the data but the API is unreliable and the documentation is from 2009. IP geolocation APIs give you approximate city from IP but can't search by name. Most 'free geocoding APIs' are wrappers around OpenStreetMap Nominatim with strict rate limits and no SLA.

Self-hosting is possible but means downloading and maintaining 100GB+ of planet data, setting up PostGIS, writing your own API layer, and hoping nothing breaks on a Sunday night. There had to be a better way.

What I Built

It's been a month since I first wrote about LocalityAPI here. Since then it's grown from 7 endpoints to 19, and from 12M places to 32.5M+. Here's where it stands today:

LocalityAPI is a REST API giving developers access to:

  • 32.5M+ global places — cities, towns, villages, suburbs, hamlets across 249 countries
  • 528M+ verified addresses — government-sourced, more coverage than HERE Maps for most use cases
  • 52.7M+ named streets
  • 7.6M+ points of interest — hotels, restaurants, hospitals, schools and more
  • 1.8M+ postal codes — covering 121 countries with coordinates and admin regions
  • IANA timezones with live local time and UTC offset
  • Sunrise & Sunset times for any location and date — a feature no other location API offers
  • IP geolocation with currency and ISP data
  • Country intelligence — currency, phone code, languages, flag for all 249 countries
  • Batch API — send 100 requests in a single HTTP call
  • Distance calculator, nearby places, reverse geocoding, address validation

19 clean endpoints. One API key. Under 20ms response time on cached requests.

The Technical Stack

Database: PostgreSQL 16 with PostGIS. The places table now holds over 32 million records with spatial indexes for radius searches and full-text search indexes for city name queries.

Data pipeline: We import from multiple sources and cross-validate. Each record gets a confidence score depending on how many independent sources agree on the data.

API layer: FastAPI with async PostgreSQL connections via asyncpg. Redis for caching frequent queries. Nginx as reverse proxy. Daily automated backups.

Response times in production (cached):

Endpoint | Response Time
/v1/search | 13-15ms
/v1/autocomplete | 10-20ms
/v1/nearby | 17-22ms
/v1/reverse | 13-15ms
/v1/timezone | ~42ms
/v1/countries | 5ms

What's New Since Launch

The biggest additions since the original 7-endpoint version:

Batch API. Send up to 100 requests in a single HTTP call, mixing different endpoint types. Built for bulk geocoding and data enrichment pipelines — uses just 1 rate limit unit for 100 results.

Sunrise & Sunset. Accurate solar times for any location and date. I added this after realizing no major location API — not Google, not HERE, not Mapbox — offers it natively.

Reverse geocoding and address validation. Coordinates to address, and address-to-confidence-score validation, both with sub-20ms cached response times.

IP geolocation. Look up country, city, currency and ISP from any IP address — useful for fraud detection and localization without asking the user anything.

The API Design Philosophy

Single header authentication. Pass X-API-Key: your_key on every request. No OAuth dance, no token refresh, no SDK required.

Consistent response shape. Every endpoint returns results, count and query_ms.

Honest about data quality. Confidence scoring tells you how reliable a record is rather than hiding it.

No forced pagination. Get the top 10 results immediately, or add limit=50 if you need more.

Code Examples

Search a city (JavaScript):
const response = await fetch(
'https://api.localityapi.com/v1/search?q=Dubai&country=AE',
{ headers: { 'X-API-Key': 'your_key_here' } }
);
const data = await response.json();
// data.results[0].name → 'Dubai'
// data.results[0].timezone → 'Asia/Dubai'

Batch request (Python):
import requests

response = requests.post(
'https://api.localityapi.com/v1/batch',
headers={'X-API-Key': 'your_key_here'},
json={'requests': [
{'endpoint': 'search', 'params': {'q': 'London', 'country': 'GB'}},
{'endpoint': 'timezone', 'params': {'city': 'Tokyo', 'country': 'JP'}},
{'endpoint': 'ip', 'params': {'ip': '8.8.8.8'}}
]}
)

One call, three results, one rate limit unit

Real Use Cases

• Address forms. /v1/countries for the dropdown, /v1/address for autocomplete, /v1/address/validate to catch typos before checkout.

• Timezone-aware notifications. One call to /v1/timezone returns IANA timezone and current local time — schedule sends correctly without storing UTC offsets yourself.

• Bulk data enrichment. Use /v1/batch to geocode a customer database overnight — 100 addresses per call instead of 100 separate requests.

• Travel and scheduling apps. /v1/sun for sunrise/sunset, /v1/nearby for points of interest, /v1/distance for trip planning — all from the same API key.

Pricing

Free tier: 1,000 calls/day. No credit card required.
Starter: $19/month for 50,000 calls/day.
Pro: $49/month for 500,000 calls/day.
Enterprise: $199/month for unlimited calls.

Compare that to Google's $500-1,700/month for similar volume.

Try It

Free tier at localityapi.com — no credit card, key in 30 seconds.
Full documentation at docs.localityapi.com

Questions? I read every email at support@localityapi.com

If you used the original 7-endpoint version, the new Batch API and Sunrise/Sunset endpoints are worth a look. I'd love to hear what you build with them in the comments.

Top comments (0)