<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bosco Edwin</title>
    <description>The latest articles on DEV Community by Bosco Edwin (@localityapi).</description>
    <link>https://dev.to/localityapi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3961272%2F0a65be31-9aa2-4710-b31e-300cd66a3f77.png</url>
      <title>DEV Community: Bosco Edwin</title>
      <link>https://dev.to/localityapi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/localityapi"/>
    <language>en</language>
    <item>
      <title>I Built a Global Location Data API with 12M+ Cities — Here's How</title>
      <dc:creator>Bosco Edwin</dc:creator>
      <pubDate>Sun, 31 May 2026 14:40:04 +0000</pubDate>
      <link>https://dev.to/localityapi/i-built-a-global-location-data-api-with-12m-cities-heres-how-4mg9</link>
      <guid>https://dev.to/localityapi/i-built-a-global-location-data-api-with-12m-cities-heres-how-4mg9</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem With Existing Solutions&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Google Maps Platform&lt;/strong&gt; 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.&lt;br&gt;
&lt;strong&gt;Free alternatives&lt;/strong&gt; 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.&lt;br&gt;
&lt;strong&gt;Self-hosting&lt;/strong&gt; 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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I Built&lt;/strong&gt;&lt;br&gt;
LocalityAPI is a REST API giving developers access to:&lt;br&gt;
• 12M+ global places — cities, towns, villages, suburbs, hamlets across 248 countries&lt;br&gt;
• 1.8M+ postal codes — covering 60+ countries with coordinates and admin regions&lt;br&gt;
• IANA timezones — for every location&lt;br&gt;
• Administrative hierarchy — countries → states/provinces → counties → cities&lt;br&gt;
• Confidence scores — each record is cross-validated across multiple authoritative sources&lt;br&gt;
&lt;strong&gt;Seven clean endpoints. One API key. Under 20ms response time.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Technical Stack&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Database:&lt;/strong&gt; PostgreSQL 16 with PostGIS. The places table has 13.5 million records with spatial indexes for radius searches and full-text search indexes for city name queries.&lt;br&gt;
&lt;strong&gt;Data pipeline:&lt;/strong&gt; We import from multiple sources and cross-validate. Each record gets a confidence score from 1-3 depending on how many independent sources agree on the data. This is something no competitor does.&lt;br&gt;
&lt;strong&gt;API layer:&lt;/strong&gt; FastAPI with async PostgreSQL connections via asyncpg. Redis for caching frequent queries. Nginx as reverse proxy.&lt;/p&gt;

&lt;p&gt;Response times in production:&lt;br&gt;
Endpoint    Response Time&lt;br&gt;
/v1/search  50-150ms&lt;br&gt;
/v1/autocomplete    10-20ms&lt;br&gt;
/v1/postal  80-120ms&lt;br&gt;
/v1/nearby  80-120ms&lt;br&gt;
/v1/countries   5ms&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The API Design Philosophy&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Single header authentication.&lt;/strong&gt; Pass X-API-Key: your_key on every request. No OAuth dance, no token refresh, no SDK required.&lt;br&gt;
Consistent response shape. Every endpoint returns results, count and query_ms. You always know where your data is.&lt;br&gt;
&lt;strong&gt;Honest about data quality.&lt;/strong&gt; The confidence field (1-3) tells you how reliable a record is. Most APIs hide this. We surface it.&lt;br&gt;
&lt;strong&gt;No forced pagination.&lt;/strong&gt; For most use cases you want the top 10 results immediately. Add limit=50 if you need more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Examples&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Search a city (JavaScript):&lt;/strong&gt;&lt;br&gt;
const response = await fetch(&lt;br&gt;
  '&lt;a href="https://api.localityapi.com/v1/search?q=Dubai&amp;amp;country=AE" rel="noopener noreferrer"&gt;https://api.localityapi.com/v1/search?q=Dubai&amp;amp;country=AE&lt;/a&gt;',&lt;br&gt;
  { headers: { 'X-API-Key': 'your_key_here' } }&lt;br&gt;
);&lt;br&gt;
const data = await response.json();&lt;br&gt;
// data.results[0].name → 'Dubai'&lt;br&gt;
// data.results[0].timezone → 'Asia/Dubai'&lt;br&gt;
// data.query_ms → 8&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Postal code to coordinates (Python):&lt;/strong&gt;&lt;br&gt;
import requests&lt;/p&gt;

&lt;p&gt;def postal_to_coords(code, country):&lt;br&gt;
    response = requests.get(&lt;br&gt;
        '&lt;a href="https://api.localityapi.com/v1/postal" rel="noopener noreferrer"&gt;https://api.localityapi.com/v1/postal&lt;/a&gt;',&lt;br&gt;
        params={'code': code, 'country': country},&lt;br&gt;
        headers={'X-API-Key': 'your_key_here'}&lt;br&gt;
    )&lt;br&gt;
    data = response.json()&lt;br&gt;
    return data['lat'], data['lng']&lt;br&gt;
 lat → 51.501, lng → -0.1247&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real Use Cases&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;•   Address forms.&lt;/strong&gt; Use /v1/countries for the country dropdown, /v1/admin for states/provinces, /v1/autocomplete for the city field. Three API calls, fully dynamic address form, no hardcoded lists to maintain.&lt;br&gt;
&lt;strong&gt;•   Timezone detection.&lt;/strong&gt; User signs up and enters their city. One call to /v1/search returns their IANA timezone. All their notifications go out at the right local time.&lt;br&gt;
&lt;strong&gt;•   Shipping validation.&lt;/strong&gt; E-commerce checkout enters postal code. One call to /v1/postal validates it exists and returns city and coordinates. Catch invalid postal codes before the order ships.&lt;br&gt;
&lt;strong&gt;•   Location-based filtering.&lt;/strong&gt; User grants location permission, you get lat/lng, one call to /v1/nearby returns all cities within 50km. Filter your database by those cities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pricing&lt;/strong&gt;&lt;br&gt;
Free tier: 1,000 calls/day. No credit card required. Sign up and get a key in 30 seconds.&lt;br&gt;
Paid plans start at $19/month for 50,000 calls/day. Compare that to Google's $500-1,700 for the same volume.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What's Coming&lt;/strong&gt;&lt;br&gt;
• Points of interest (restaurants, hotels, hospitals, landmarks)&lt;br&gt;
• Reverse geocoding (lat/lng to full address)&lt;br&gt;
• Street-level address search&lt;br&gt;
• Administrative boundary polygons&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Try It&lt;/strong&gt;&lt;br&gt;
Free tier at &lt;u&gt;localityapi.com&lt;/u&gt; — no credit card, key in 30 seconds.&lt;br&gt;
Full documentation at &lt;u&gt;docs.localityapi.com&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;Questions? I read every email at &lt;a href="mailto:support@localityapi.com"&gt;support@localityapi.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;_If you found this useful, a like or share helps others find it. And if you build something with LocalityAPI, I'd love to hear about it in the comments.&lt;br&gt;
_&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>api</category>
    </item>
  </channel>
</rss>
