Why it exists
A coordinate pair doesn't mean much to most people. “2.3 miles NW of Millhousen, IN” does. Weather alerts, storm reports, field notes and dispatch logs all describe places this way.
For years this site got that answer from the National Weather Service's /points API,
which returned a relativeLocation for every forecast point. NWS changed that API in June 2026,
so nearest.town now runs its own small API that gives the same kind of answer from the same Census place list.
Why not just reverse-geocode to a street address? Because an address names the post office that serves a point, which in rural areas can be a town many miles farther away than the one you're actually near.
How it works
Each lookup gives exactly one answer, chosen in two steps:
- Inside a town? If the point falls within a town's boundary, that town is the answer. Great American Ball Park returns Cincinnati, OH, even though Newport, KY's center is closer across the river.
- Otherwise, the nearest center. If the point isn't inside any town, the answer is the town whose center point is closest by great-circle (haversine) distance. This matches how the NWS API used to behave.
In both cases, the distance and direction are measured from the town's center to your point. That's why a point inside Cincinnati still reads “3.0 miles S of Cincinnati, OH”. The direction is rounded to one of 16 compass points (N, NNE, NE, …).
The data
- Towns: the 2025 Census Gazetteer “Places” file, about 32,350 places. That includes cities, towns, villages and boroughs, unincorporated communities (Census Designated Places), and Puerto Rico's zonas urbanas and comunidades.
- Centers: each place's Census internal point, roughly the middle of its land area. It is not necessarily downtown.
-
Boundaries: the Census cartographic boundary file
(
cb_2025_us_place_500k), simplified to 1:500,000 scale. - Names drop the Census type suffix (“Millhousen town” → “Millhousen”), and consolidated city-counties use their common name (“Nashville-Davidson metropolitan government (balance)” → “Nashville”).
Use the API
The API is free, read-only, needs no key, and allows calls from any website (CORS is open).
Request
GET https://nearest.town/api/nearest/{lat},{lon}
GET https://nearest.town/api/nearest?lat={lat}&lon={lon}
Coordinates are plain decimal degrees (up to 10 decimal places), with latitude between −90 and 90 and longitude between −180 and 180.
Examples
curl https://nearest.town/api/nearest/39.237535,-85.461877
const res = await fetch("https://nearest.town/api/nearest/39.237535,-85.461877");
const place = await res.json();
console.log(place.text); // "2.3 miles NW of Millhousen, IN"
Response
{
"query": { "lat": 39.237535, "lon": -85.461877 },
"town": {
"name": "Millhousen", "state": "IN", "type": "town",
"geoid": "1849662", "lat": 39.211988, "lon": -85.434165
},
"inside": false,
"distance": { "meters": 3711, "miles": 2.31 },
"bearing": 320,
"direction": "NW",
"text": "2.3 miles NW of Millhousen, IN"
}
| Field | Meaning |
|---|---|
query | The coordinates you sent. |
town.name, town.state | Town name and two-letter state (or PR, DC). |
town.type | Census place type, such as city, town, village or CDP. |
town.geoid | Census GEOID: 2-digit state FIPS code plus 5-digit place code. |
town.lat, town.lon | The town's center (Census internal point). |
inside | true if your point is within the town's boundary. |
distance | From the town center to your point, in meters and miles. |
bearing | Compass bearing in degrees (0–359) from the town center to your point. |
direction | The bearing as one of 16 compass points. |
text | A ready-to-display sentence. |
Errors and limits
| Status | When |
|---|---|
400 | Coordinates missing, malformed or out of range. |
429 | More than 600 requests per minute from one IP address. Wait for the number of seconds in the Retry-After header. |
404 | Unknown path. |
Error bodies look like {"error": "…"}. Successful answers can be cached for a day.
GET https://nearest.town/api/health reports the service status and which data vintage is loaded.
Limitations
- The center isn't downtown. In large or merged city-counties the center can be far from downtown. Downtown Anchorage reads “20.7 miles W of Anchorage, AK”.
- Town lines are approximate. Boundaries are simplified, so a point within a few meters of a town line can land on either side.
- US places only, no coverage limit. A point in Canada, Mexico or the ocean still gets the nearest US place, however far away.
- Census vintage. New incorporations and annexations appear once the Census publishes them.