APIs
Geocoding API
A geocoding API turns an address or a place name into coordinates. The oslew geocoder returns ranked candidates, and each one says what it actually matched, how often answers like it are right, whether other candidates tied for first, and under which licence the record may be kept. It runs on every plan, Free included, and the Address plan is $99 a month for 20 requests a second sustained, burst 100, with no monthly quota to watch.
Last reviewed
A geocode is one request, GET /v1/geocode?q=…, and one answer: a ranked list of candidates for what the text meant. What makes the answer useful is not the coordinates — every geocoder returns those — but the fields around them, which say how far to trust each candidate and what you are allowed to do with it.
How the text is read
The query is split once, at its last comma. Everything before it is the name: a street and house number, or the name of a place. Everything after it is context — one postcode, one city, one region or one country — and context is resolved before a single candidate is scored. It is matched as written, as an ISO code, and by containment in any administrative division bearing that name, so Ciudad de México, CMX and MX-CMX all narrow the search to the same place.
That split is the most important thing to get right in an integration. A colonia or a second address line left in the middle becomes words the name has to match, and no address row contains them. Send the street and number, a comma, and the single piece of context that narrows the most — usually the postcode — and nothing in between.
Before matching, the same normalisation runs on the query as ran on the index when it was built: case and accents are folded, punctuation becomes a space, word order stops mattering, and common street abbreviations collapse to one form. A house number glued to its street is taken apart. A word the index has never seen is tried as a transposition, then as a single edit, then as two known words run together.
What each candidate tells you
Every result carries the same set of fields, and reading them is most of the work of integrating a geocoder well:
- Precision says what matched — an address point, an interpolated position, an address row without its number, a street, or a place — together with an estimate in metres of how wrong the position can be. It is reported from what actually matched, never from what the query asked for. Precision levels explains how to act on each.
- Confidence is calibrated: it says how often answers of this shape have turned out to be right, not how similar two strings are.
- tied_at_top counts the candidates that scored equal first, over every candidate the search kept, before your
limitcut the list. A value above one means the question did not have one answer. - why records what drove the ranking, so a surprising result can be explained rather than argued with.
- Provenance names the dataset and release each record came from and its licence code, per result.
- Normalised components give the address back in a consistent form, ready to store.
When a query carries a house number the data does not hold, the geocoder can place it between the recorded numbers either side on the same street — interpolation — but never across a gap wider than 1 km, and never beyond the highest or lowest recorded number. An interpolated answer says so in its precision and lists the two numbers it was placed between.
The biggest lever is what you send
Accuracy is measured on addresses removed from the index before it was built, so every test address is one the engine has never seen. Measured on Mexico City held-out numbered addresses, a query carrying the postcode lands a median 19 m from the true point, with 67.2% within fifty metres. The same addresses sent with only the city land a median 162 m away, because a city name leaves the engine choosing between every same-named street in a metropolis. The accuracy page publishes every row, including the ones that do not flatter the engine.
A worked example
curl -H "Authorization: Bearer $OSLEW_KEY" \
"https://api.oslew.com/v1/geocode?q=Avenida+Insurgentes+Sur+1602,+03940"The answer echoes how the text was split — Avenida Insurgentes Sur 1602 as the name and 03940 as the context — and reports whether the context was recognised at all. If nothing satisfied it, the search runs again without it and says so with a fallback flag, rather than silently answering from somewhere else. The first candidate’s precision says whether the house number matched a recorded address point; its confidence and tie count say whether to act on it or to ask. The same three checks, in that order, are the whole of a robust integration.
For a person typing into a form, pair this with autocomplete while they type and validation when they submit. For a file of existing addresses, batch geocoding runs the same engine over the whole file at your plan’s rate.
What it costs
Geocoding is part of the Address product, which every plan includes. The Free plan allows 1 requests a second sustained, burst 5, enough to build against. The Address plan is $99 a month for 20 requests a second sustained, burst 100. That is a rate, not an allowance: there is no monthly count to exhaust, no overage, and a retry or a spike costs nothing extra. Going faster than the plan returns HTTP 429 with a Retry-After header, and waiting is enough.
Limits worth knowing
- There are no
country,bbox,languageortypesparameters. Context after the last comma does the narrowing, and a parameter the route does not take is ignored rather than refused. - The
nearparameter is a hard filter to a fixed grid cell, not a preference for nearby results; used as a preference, it will silently drop the right answer when it sits just outside the cell. - Accuracy figures above were measured on one city’s held-out addresses. How the geocoder does elsewhere depends on the address data loaded there, and on the same thing — how much context each query carries.
Bottom line
If you need to turn addresses into coordinates at a predictable cost, this is the endpoint, and the answer tells you when not to trust it. Send the postcode, read precision and the tie count before the coordinates, and store the provenance with anything you keep. Address and place results are permissively licensed; anything drawn from administrative boundaries is ODbL, and the licensing page sets out what share-alike asks of a database you share.
Questions
What is the difference between geocoding and reverse geocoding?
Geocoding goes from text to coordinates: an address or a place name in, candidate locations out. Reverse geocoding goes the other way, from a coordinate to the nearest addresses and places and the administrative areas around it. oslew serves both on the Address product, from the same rate.
How do I get the most accurate geocoding result?
Send the postcode as the text after the last comma. Measured on Mexico City held-out numbered addresses, that takes the median error to 19 m, against 162 m with only the city. Both narrow the search before anything is scored, but a postcode confines it to a small area where a city leaves the whole metropolis in play.
Does the geocoder cope with typos and abbreviations?
Yes. Abbreviations such as av, avda and ave fold to one word in the index and the query alike, and a misspelt word is repaired and labelled fuzzy, so a salvaged answer can never pass for an exact one. The geocoder does not transliterate or translate: a name is matched in the script it was recorded in.
Can I restrict results to one country or a bounding box?
There is no country or bounding-box parameter. Put the country, region, city or postcode after the last comma instead, where it is resolved as context and narrows the search. The near parameter keeps only candidates in the grid cell of about 10 km around a point, as a filter rather than a bias.
How many candidates does one request return?
Up to 50 results, ranked. Most applications act on the first, but only when tied_at_top is one. When several candidates tie, the text does not determine a single place, and the right move is to ask the person which one they meant rather than to guess.