Autocomplete an Address
Problem: A user is typing an address. I need suggestions without billing per keystroke.Prerequisites
- A HERE API key with Geocoding & Search entitlement
export HERE_API_KEY="..."
/autocomplete and /autosuggest are not synonyms.Picking the wrong one produces a type-ahead that feels broken to users and correct to engineers.
The code
Response walkthrough
id — the HERE ID. Store it. When the user selects a suggestion, resolve it with /v1/lookup rather than re-geocoding the label string.
highlights — character offsets of the matched substring. Bold them in the dropdown.
No position. Autocomplete returns addresses, not coordinates. Resolve the selected item.
Common mistakes
No debounce. One transaction per character. NoAbortController. The user typed “425 W Ra” — the response for “425 W R” is already stale and you are still paying to receive it.
Firing below three characters. "1" matches nothing useful and bills anyway.
Using /autosuggest for an address field. It returns places and categories. Users get “Randolph Street Market” where they wanted an address.
Using /autocomplete for a search box. No typo tolerance, no places.
Sending q and qq together. HERE’s own guidance: this produces inconsistent scoring. That applies to /geocode; keep autocomplete queries clean.
Not passing at. Location bias improves relevance materially and costs nothing.
Re-geocoding the selected label instead of /lookup by id.
Shipping the API key to the browser without a domain restriction. Any key in frontend JavaScript is public.
Production considerations
Debounce at 200–300ms. Below 200ms you bill for typing pauses. Above 300ms it feels laggy. Cancel superseded requests.AbortError is a normal outcome, not a failure to log.
Proxy through your backend. Keeps the key private, gives you a cache layer and per-tenant metering. Costs latency. Decide deliberately.
Restrict browser-exposed keys by domain. If it has no restriction, it is now someone else’s key and someone else’s invoice.
Cache selections permanently, keyed on the HERE ID. See Caching Geocoding Results.
Prevention beats correction. An address entered from a validated suggestion does not need fixing later. This is the cheapest address-quality intervention available. See Address Validation.
Related
Geocoding and Search
Seven endpoints, one correct choice per job.
Search Nearby POIs
/discover and /browse — the endpoints autocomplete is not.Address Validation
Prevention at the source.
Cost Optimization Patterns
Pattern 1: the keystroke is the wrong unit of work.
HERE documentation
Need production HERE API keys or implementation support? Placematic is an official HERE Technologies reseller and implementation partner. Talk to us.