Skip to content
news / search-as-you-type · raw .md
MapsUpdated 6 min readMapMap engineering
A stack of narrow horizontal rows of decreasing length, each row tethered by a fine leader line to a small cross marker placed on a sparse coordinate field.

Our suggestions carry coordinates, so a pin is free

GET /geocode/suggest returns search-as-you-type suggestions, and every one of them carries its own lat and lon. A map that only needs to drop a pin can plot the pick from the suggestion alone and never call a second endpoint. The first 5,000 suggests of each UTC day draw no units at all, counted across every key on the account, so a search box on an ordinary site costs nothing to run.

Why do suggestions include coordinates?

Because the coordinate is right there in the index, and there is no technical reason to hold it back. This is the one place our search API deliberately differs from the shape the market has settled on: Mapbox's suggest response withholds lat and lon so that every pick must be followed by a retrieve call. Ours does not.

Two things follow. A client that needs only a point never makes the second call, which takes a search box inside the daily allowance to zero. And suggestions are cacheable on your side, which the withholding shape quietly prevents.

sh
curl -fsS "https://api.mapmap.ai/geocode/suggest?q=Downing+Str&bias=-0.1278,51.5074&limit=5"

The first two of the five rows that came back on 25 November 2026, coordinates trimmed to five decimal places:

json
{
  "suggestions": [
    {
      "id": "osm:w4244999:street",
      "name": "Downing Street",
      "context": "Westminster, London, England, United Kingdom",
      "kind": "street",
      "lat": 51.50320,
      "lon": -0.12668
    },
    {
      "id": "osm:r1879842:poi",
      "name": "10 Downing Street",
      "context": "Westminster, London, England, SW1A 2AA, United Kingdom",
      "kind": "poi",
      "lat": 51.50343,
      "lon": -0.12750
    }
  ]
}

The street comes first and the building second, and both are plottable as they stand. The other three rows were 9, 11 and 12 Downing Street.

What is the difference between suggest and geocode?

They answer different questions, and a search bar asks both. A search bar is not one geocode: it is a dozen partial queries as somebody types, then one lookup of the row they picked. The partial queries want a small, cheap, immediately renderable list. The pick wants the whole feature.

EndpointForReturns
GET /geocode/suggestEach debounced keystrokeUp to 10 short rows with id, name, context, kind, lat, lon
GET /geocode/retrieveThe row the user pickedThe full Photon-shaped FeatureCollection for exactly that document
GET /geocodeA single-shot lookup with no typingThe same feature shape, from a query rather than an id

On suggest, the trailing token matches as a prefix, so Downing Str reaches Downing Street, while every earlier token must be a completed word. limit runs from 1 to 10, and 11 is a 400 rather than a silent clamp. bias takes a lon,lat map centre and reorders candidates towards it without ever excluding one; zoom scales that bias, exactly as on /geocode; and bbox is the hard filter that does exclude.

GET /geocode/retrieve?id=… returns the same feature, from the same shaper, that GET /geocode would have returned for that document. Ids are matched verbatim, with no folding, trimming or case change, and they are stable within an index build but not across one. An id that was never issued, or that predates a rebuild, is a 404 whose detail tells you to search again and re-pick, never a plausible wrong document. GET /geocode/retrieve?id=osm:r1879842:poi returns the full record for the second row above: house number 10, street, postcode SW1A 2AA, category government and the building's website.

What does a search box actually cost?

The typed part is free at ordinary volumes and the pick is not.

  • The first 5,000 GET /geocode/suggest requests of each UTC day draw no units.
  • The allowance is pooled across every key on the identity, so minting a second key does not buy a second allowance.
  • It resets at midnight UTC, and it is an allowance for this one endpoint: unused suggests never become included volume for anything else.
  • Beyond it, a suggest bills one standard call, as it always did.
  • GET /geocode/retrieve is one standard call every time, and so is GET /geocode. Neither is discounted.

Your client-side debounce is what keeps a busy box inside the allowance. At the SDK's 250 ms default a typed word costs a call or two rather than one per keystroke, so 5,000 covers roughly 1,700 to 2,500 searches a day rather than about 625 undebounced ones.

Keys on an unverified provisional identity are outside the allowance and bill per call. A provisional key meters against a lifetime pool rather than a month, and a daily allowance inside a lifetime pool would outlive the pool. Verify the email and the allowance applies.

Do I have to build the dropdown myself?

No. SearchBox in @mapmap/maps is a drop-in MapLibre IControl: debounced suggestions as the user types, arrow-key navigation, a typed "select" event with the picked feature, and optionally a fly-to and a marker. Like our logo control it is typed structurally, so it imports maplibre-gl neither at module load nor at runtime.

ts
import { MapMapMap, SearchBox } from "@mapmap/maps";

const map = new MapMapMap({ container: "map", apiKey: "snk_…" });
const search = new SearchBox({ apiKey: "snk_…" });
search.on("select", ({ suggestion, hit }) => {
  console.log(suggestion.name, hit?.postcode);
});
map.map.addControl(search, "top-left");

hit is the full record from the retrieve and is undefined when that call failed. The suggestion's own coordinates always survive, so a failed retrieve still leaves you with a usable point. If you only need a point, ignore hit entirely and you never pay for search inside the allowance.

For a search UI of your own, the wire helpers are exported too: buildSuggestUrl, buildRetrieveUrl and parseSuggestResponse. The API key is never embedded in a built URL, because it belongs in a bearer header.

The control also fires the quota-free POST /geocode/selection relevance ping when a result is picked, so what your users actually choose feeds back into ranking. It is fire-and-forget: a refused ping never surfaces to the user and never delays the "select" event.

What this does not cover

Both endpoints need the first-party index. On a deployment that only proxies Photon, or one whose index predates the document-id field, they answer 501 with urn:sn-gateway:problem:suggest-not-enabled. A client should feature-detect on that and fall back to GET /geocode with the typed query.

lang does not currently change the answer. It is accepted for symmetry with /geocode, and the first-party index stores one name per document plus its alternatives, so a language parameter has nothing to select between yet.

Ids do not survive an index rebuild. Caching a suggestion's coordinates is fine and is encouraged. Caching an id as a long-lived foreign key is not, because the next build may not issue it.

The allowance is not a free geocoding tier. It covers the typing, not the answering. A batch job that resolves 5,000 addresses is 5,000 standard calls on POST /geocode/batch, and nothing about this changes that.

Try it

Both endpoints are open to maps-scoped browser keys and both are on the keyless demo lane, so the request above runs without a key at all. The parameter tables are in the search-as-you-type section of the API reference, the control's options are in the web maps guide, and the engine behind all of it is the one described in First-party geocoding: one engine, online and offline.