apidata.one docs Get a key

Autocomplete: a search box that completes

One call serves a search box: GET /v1/autocomplete answers what the visitor may mean, in groups, from the second character on. This guide shows what to send, and what to do with each kind of suggestion.

GET /v1/autocomplete?q=ardm
{
  "data": {
    "places": [ { "placeId": "pl_…", "kind": "cdp", "displayName": "Ardmore (CDP), Montgomery County, PA", "state": "PA", "center": { "lat": 40.01, "lng": -75.29 } } ],
    "postalCodes": [],
    "addresses": [ { "listingKey": "805454359664", "mlsNumber": "PAMC2141234", "status": "active", "address": { "line1": "12 ARDMORE AVE", "unit": null, "city": "Ardmore", "state": "PA", "postalCode": "19003" } } ],
    "mlsNumbers": []
  },
  "meta": { "requestId": "req_…", "environment": "test" }
}

Each group holds at most ten suggestions. Show them under headings, in the order you like.

What to do with a suggestion

Group The visitor chose Then
places a town, a county, a township, a community, a subdivision Search it by its ID: GET /v1/listings?location.placeIds=pl_…. Move your map to the place with GET /v1/places/{placeId}, which gives its bbox
postalCodes a ZIP code Search it by location.placeIds with its placeId, or by location.postalCodes=19003
addresses one listing, by its address Go to that listing's page, by its listingKey
mlsNumbers one listing, by a current or past MLS number Go to that listing's page, by its listingKey
schoolDistricts (Premium) a school district Search it by location.placeIds with its placeId

Ask for the groups you show

types names the groups you want, and leaves the rest out of the answer:

GET /v1/autocomplete?q=1908&types=postalCodes,places
GET /v1/autocomplete?q=PAMC21&types=mlsNumbers

Nearest first

near=lng,lat orders each group by distance from a point: the center of the map on screen, or the visitor's own position if they shared it.

GET /v1/autocomplete?q=spring&near=-75.30,40.02

In the browser

A search box runs in the browser, so call with your publishable key from one of your account's website addresses:

const box = document.querySelector('#search');
let timer = null;
let running = null;

box.addEventListener('input', () => {
  clearTimeout(timer);
  const q = box.value.trim();
  if (q.length < 2) return showSuggestions(null); // nothing is searched under two characters
  timer = setTimeout(async () => {
    running?.abort(); // an older answer must not overwrite a newer one
    running = new AbortController();
    try {
      const r = await fetch(`https://api.apidata.one/v1/autocomplete?${new URLSearchParams({ q })}`, {
        headers: { Authorization: 'Bearer pk_test_…' },
        signal: running.signal,
      });
      if (r.ok) showSuggestions((await r.json()).data);
    } catch {
      // aborted, or offline: leave what is shown
    }
  }, 200);
});

Autocomplete finds places, ZIP codes and listings. It is not a geocoder: an address that is not a listing's finds nothing. Neighborhoods and individual schools are not places yet.

This page as Markdown