Town and city search clients for geo.chofter.com: about 237,000 places in 246 countries from GeoNames, served as static JSON files. There is no API and no key. A client works out which file holds the answer, fetches it from the CDN and ranks the results itself.
| Language | Folder | Package |
|---|---|---|
| JavaScript | js/ |
@chofter/geo |
The landing page has sample code for Python, Ruby, Go, C# and Java in the meantime.
Everything is relative to the base URL, https://geo.chofter.com/v1.
countries.json:[code, name, count, altNames?]per country. The UK is listed as its four nations,GB-ENG,GB-SCT,GB-WLSandGB-NIR, each withaltNames["United Kingdom", "UK"].{cc}/_.json:{ name, depth, count, shards, top }, whereccis the lowercase ISO 3166-1 alpha-2 code, or a nation's code such asgb-eng. For a small countrydepthis 0,shardsis empty andtopholds every place.{cc}/{key}.json: an array of places for one prefix.- A place is
[name, region, lat, lng, population, geonameId, altNames?, district?, localName?, city?]. Trailing items are left out, and one that is missing before a present one is[](altNames) or"".district(a county or district) is there only when another place in the country has the same name and region. Show it in the label, as in "Plantation, Broward County, Florida, United States".localNameis the name in the country's first official language, such as "서울" for Seoul, when that language is not English and the name differs fromname. It is searchable like an alternate name.cityis set for a suburb: the city it is part of. Show it after the name, as in "Leichhardt, Sydney, New South Wales, Australia". The label isname,city,district,regionand the country, leaving out empty ones.
- In Ireland a place's region is its county, and in the UK its council area.
gb/_.jsonholds the whole UK. It also hasparts, each nation's code and name, andregionParts, the nation of each region, so a search ofGBcan report each place's nation as its country.
q = normalize(query). Ifqis empty, return the firstlimitplaces oftop.- If
depthis 0, the candidates aretop. Otherwise, fornfrommin(depth, length of q in code points)down to 1, take the firstncode points ofq; the first whosefileKeyis inshardsnames the file to fetch. If none is listed, return nothing. - A candidate matches if
normalizeof its name, an alternate name or itslocalNameequalsq(tier 0), or starts withqor contains" " + q(tier 1). Use the best tier over all its names, and remember which name gave it. - Sort by tier, then by population descending (a stable sort), and return the
first
limit(default 10). Report the alternate name that matched, if it was not the main name. If the index hasregionParts, a place's country is the part its region maps to.
normalize and fileKey are defined in conformance/, which
also holds the cases every client must pass.
This repository is mirrored from a private one, so pull requests are applied by hand. Issues are welcome.
Code style is checked with oxlint
(npm run lint in js/, using .oxlintrc.json): every if, else, for,
while and do body uses braces. Formatting is
oxfmt (npm run format, using .oxfmtrc.json).
Code: MIT. Data: GeoNames, CC BY 4.0; credit GeoNames wherever you show results.