Handle landmark and relative-place queries
Use this procedure when users type a place nametoponymA proper name for a geographic place., such as Empire State Building, or a description, such as Behind the gas station, where your application expects an address. The geocoder can return a coordinate for both. This guide shows how to tell a matched place from a coordinate that locates something other than what the user asked for.
This guide applies one rule. Use a coordinate only when the result's resolution_tier is venue and its entity field holds the matched place, and show that entity to a person before relying on it. For every other result, ask for an address.
Prerequisites
^24.22.3 || >=26.13.1"type": "module" in its package.jsonStart by installing the required packages:
- npm
- Yarn
- pnpm
- Bun
npm install mailwoman
yarn add mailwoman
pnpm add mailwoman
bun add mailwoman
Place namestoponymA proper name for a geographic place. resolve against the point-of-interest database. Download it with the global place candidates:
export MAILWOMAN_DATA_ROOT="$HOME/mailwoman-data"
npx mailwoman data pull candidate poi
The two bundlesevidence bundleThe pair of retrieval-augmented input channels (street-type + locality-surface) that feed lexicon membership as soft per-token evidence alongside the text. Shipped in 6.7.0; trained natively from step 0 in the from-scratch base line. download about 6.8 GB: candidate 2.9 GB and poi 3.9 GB. The poi bundleevidence bundleThe pair of retrieval-augmented input channels (street-type + locality-surface) that feed lexicon membership as soft per-token evidence alongside the text. Shipped in 6.7.0; trained natively from step 0 in the from-scratch base line. covers the US, Canada, Mexico and France. The output below was captured with local builds of both bundlesevidence bundleThe pair of retrieval-augmented input channels (street-type + locality-surface) that feed lexicon membership as soft per-token evidence alongside the text. Shipped in 6.7.0; trained natively from step 0 in the from-scratch base line. that are newer than the 11.1.0 registry entries, so your coordinates and confidence values can differ.
1. Geocode the queries
Save these three queries as landmarks.txt:
Empire State Building
Eiffel Tower, Paris
Behind the gas station
Geocode them:
npx mailwoman geocode --stdin < landmarks.txt > landmarks.jsonl
Each line of landmarks.jsonl has a components.venue value, because the parser read each query as a place nametoponymA proper name for a geographic place.. The geocoder's answers differ:
| Input | resolution_tier | epistemic_status | Coordinate | entity |
|---|---|---|---|---|
Empire State Building | venue | observed | 40.749143, -73.986621 | Empire State Building, category historic_site, confidence 0.95 |
Eiffel Tower, Paris | venue | observed | 48.87296739, 2.29785971 | Eiffel tower, category monument, confidence 0.93 |
Behind the gas station | admin | unresolved | null | null |
The confidence values in the table are rounded to two places.
2. Recognize a query with no place to return
For Behind the gas station, the parser read the whole input as a venuevenueA named, non-address place — a business, building, park, or stadium. Mailwoman's free-text point-of-interest component, added as a Tier 2 fine label., and no point of interestpoint of interest (POI). A named place that is not strictly an address — landmark, transit stop, venue, amenity, or franchise. Mailwoman tags these as venue and resolves them through the gazetteer. matched it. The geocoder then looked for a town spelled by part of the input and matched the last word, station, to a town called Station in Kentucky, Who's On FirstWOF (Who's On First). An open-source gazetteer of places maintained by Mapzen/whosonfirst. Mailwoman builds a custom SQLite database from WOF GeoJSON repos, extended with postcode data, importance scores, and coincident-role relations. place wof:1343272895. That match drops the rest of the input, so the geocoder keeps it only when a venuevenueA named, non-address place — a business, building, park, or stadium. Mailwoman's free-text point-of-interest component, added as a Tier 2 fine label. answers near the town. None does, so the result is unresolved, with no coordinate and no entity. Version 11.0.0 returned the Kentucky town's point here with epistemic_status: "observed".
The user described a spot relative to their own position. A relative description such as "behind", "near" or "across from" depends on where the user is, so a gazetteergazetteerA geographical index that maps place names and postcodes to real-world coordinates. Mailwoman uses a custom-built Who's On First (WOF) SQLite database as its gazetteer — the 'atlas' half of the grammar/atlas architecture. lookup by place nametoponymA proper name for a geographic place. can't resolve it. When a query has a venue component and the result's tier is anything other than venue, a non-null lat and lon locate some other place.
3. Check the matched place
A venue result is a point-of-interest record whose name matched the query. Read its entity before using the coordinate:
{
"name": "Eiffel tower",
"categoryID": "monument",
"confidence": 0.9292718768119812,
"country": "FR"
}
The matched record is called Eiffel tower, in the monument category. Its coordinate, 48.87296739, 2.29785971, lies about 1.6 km north of the Eiffel Tower. The tower stands on the Champ de Mars, near 48.8583, 2.2945. confidence scores how well the name matched. Show the entity's name and category, and a map pin when you can, so a person can confirm the place.
4. Route each result
Save this script as route-landmarks.ts. It applies the rule from the start of this guide to each result:
import { readFileSync } from "node:fs"
interface GeocodeRow {
input: string
components?: Record<string, string>
resolution_tier: string
lat: number | null
lon: number | null
entity: {
name: string
categoryID: string | null
confidence: number
} | null
}
const rows: GeocodeRow[] = readFileSync("landmarks.jsonl", "utf8")
.trim()
.split("\n")
.map((line) => JSON.parse(line))
function route(row: GeocodeRow): string {
const asked = row.components?.venue
if (!asked) return "not a place-name query: geocode as an address"
if (row.resolution_tier === "venue" && row.entity) {
const { name, categoryID, confidence } = row.entity
return `candidate place: ${name} (${categoryID ?? "no category"}, confidence ${confidence.toFixed(2)}) at ${row.lat}, ${row.lon} — confirm before use`
}
const coordinate = row.lat == null ? "no coordinate" : `the ${row.resolution_tier} coordinate locates another place`
return `no place found for "${asked}": ${coordinate} — ask for an address`
}
for (const row of rows) {
console.log(`${row.input}\n ${route(row)}`)
}
node route-landmarks.ts
Empire State Building
candidate place: Empire State Building (historic_site, confidence 0.95) at 40.749143, -73.986621 — confirm before use
Eiffel Tower, Paris
candidate place: Eiffel tower (monument, confidence 0.93) at 48.87296739, 2.29785971 — confirm before use
Behind the gas station
no place found for "Behind the gas station": no coordinate — ask for an address
Keep the user's original text with each routed result. When you ask for an address, show what was typed so the user can correct it.
When a landmark layer is installed
The geocoder also reads an optional landmarks.db file from the directory that holds poi.db. The 11.1.0 data bundlesevidence bundleThe pair of retrieval-augmented input channels (street-type + locality-surface) that feed lexicon membership as soft per-token evidence alongside the text. Shipped in 6.7.0; trained natively from step 0 in the from-scratch base line. ship without it. When it is present, a matched landmark sets coordinate_source to the layerlayerOne transformer block — attention plus a feed-forward network, with normalization and residual connections — applied to every position. Stacking layers lets the model build up richer representations; Mailwoman's encoder has 6.'s source, such as wikidata, with release: null. With a landmark layerlayerOne transformer block — attention plus a feed-forward network, with normalization and residual connections — applied to every position. Stacking layers lets the model build up richer representations; Mailwoman's encoder has 6. on the host used for this page, Eiffel Tower, Paris returned 48.858296, 2.294479 and Empire State Building returned 40.748333333333335, -73.98555555555555. Behind the gas station was unresolved either way. The routing rule above applies to both setups, because it reads resolution_tier and entity rather than the coordinate's source.
Related
- Result schema describes
resolution_tier,entityandcoordinate_source. - Handle PO boxes, intersections and bare postcodes cover the other inputs that differ from streetstreetThe named linear feature along which house numbers are ordered. Decomposes into a name plus street affixes; one of the Tier 2 fine labels. addresses.
- Confidence and limits explains why a match score measures the name match and leaves the coordinate unchecked.