Address autocomplete
Suggestions for partial input, tuned for latency and typo tolerance. Every suggestion carries coordinates, so most integrations never need a second call.
GEThttps://api.mygeocode.com/v1/autocomplete
Parameters
| Parameter | Type | Description |
|---|---|---|
qrequired | string | What the user has typed so far. At least 2 characters, up to 128. |
limitoptional | integer | 1 to 10. Default 5. |
countriesoptional | string | Comma-separated ISO 3166-1 alpha-2 codes to restrict suggestions to. |
proximityoptional | string | lat,lon. Nearby suggestions rank first. Strongly recommended for map search boxes. |
typesoptional | string | Comma-separated subset of address, street, postcode, city, region, country, poi. Default all. |
langoptional | string | ISO 639-1 code. Default en. |
keyoptional | string | API key, if not sent as a header. |
Example
$ curl "https://api.mygeocode.com/v1/autocomplete?q=oxford+st&proximity=51.515,-0.141&limit=3"const url = new URL("https://api.mygeocode.com/v1/autocomplete");
url.searchParams.set("q", "oxford st");
url.searchParams.set("proximity", "51.515,-0.141");
url.searchParams.set("limit", "3");
const { suggestions } = await (await fetch(url)).json();
suggestions.forEach((s) => console.log(s.text, s.lat, s.lon));import requests
r = requests.get("https://api.mygeocode.com/v1/autocomplete",
params={"q": "oxford st", "proximity": "51.515,-0.141", "limit": 3}, timeout=5)
for s in r.json()["suggestions"]:
print(s["text"], s["lat"], s["lon"])Response
{
"status": "ok",
"query": "oxford st",
"suggestions": [
{ "text": "Oxford Street, London W1, United Kingdom", "lat": 51.515419, "lon": -0.141588, "type": "street", "precision": "street", "place_id": "gb.street.0a91e2c4" },
{ "text": "Oxford Street, Southampton SO14, United Kingdom", "lat": 50.899021, "lon": -1.399537, "type": "street", "precision": "street", "place_id": "gb.street.77b4d1f0" },
{ "text": "Oxford Street Station, London W1, United Kingdom", "lat": 51.515167, "lon": -0.141251, "type": "poi", "precision": "house", "place_id": "gb.poi.3c5a8e19" }
]
}Response fields
| Field | Type | Description |
|---|---|---|
suggestions[].text | string | Display text, one line, in lang. |
suggestions[].lat, lon | number | Coordinates. Always present. |
suggestions[].type, precision | string | As in forward geocoding. |
suggestions[].place_id | string | Pass to /v1/forward?place_id=... for full components and bounds. That call counts as one request. |
Notes
- Debounce input to around 150 ms and cancel in-flight requests when the user keeps typing. Responses carry the
querythey answer, so you can discard stale ones. - There are no session tokens. Each call is one request. A typical address takes 4 to 6 calls to pick.
- Calling from the browser on the free tier is the intended use for public sites. The visitor's IP is counted, not yours.
- The Google
places.Autocompletewidget, Mapbox Search Box, HERE Autosuggest and Bing Autosuggest formats are available on the drop-in hosts.
The same lookup in other providers' formats
If you already have code written against one of these providers, keep it: the drop-in host accepts the same path and parameters and answers in that provider's response shape, with this endpoint behind it. See how the drop-ins work.
| Provider | Host | Path |
|---|---|---|
| Google Maps Platform | gapi.mygeocode.com | /maps/api/place/autocomplete/json?input=... |
| Bing Maps REST Services | bing.mygeocode.com | /REST/v1/Autosuggest?query=... |
| HERE Geocoding and Search | here.mygeocode.com | /v1/autosuggest?q=...&at=lat,lng/v1/autocomplete?q=... |
| Mapbox Geocoding | mapbox.mygeocode.com | /search/searchbox/v1/suggest?q=... |
| LocationIQ | locationiq.mygeocode.com | /v1/autocomplete?q=... |
| Geoapify | geoapify.mygeocode.com | /v1/geocode/autocomplete?text=... |
| TomTom Search | tomtom.mygeocode.com | /search/2/search/{query}.json?typeahead=true |
Errors
400 invalid_request when q is shorter than 2 characters, or types contains an unknown value.