Place Autocomplete (/core/geography/place/autocomplete) is a wrapper service for Google's Place
Autocomplete API, which returns place predictions based upon a user input string. It can be used in conjunction with [Google Place Details]
to validate user input and retrieve geographic information. Please refer to
Google's documentation for information about this service.
NOTE: Aside from autocompleting user input, Place Autocomplete is also the geo service to use for validating or normalizing non-street address location types, such as cities or zip codes.
All requests require a UUID session token. Session tokens are used by Google to group multiple requests into one billing session.
As an example of the intended usage of sessions, suppose a consumer of the Place Autocomplete and Place Details apis has a user searching for a place:
- A session token UUID
Ais generated for the session. - The user begins typing a place name.
- On e.g. the third keystroke
"Har"a request is sent to/core/geography/place/autocompletewithinput:Harandsession_token:A. - A list of predictions and their
place_ids are generated for"Har"and returned in the response. - The user does not select any of the predictions and instead inputs another keystroke
"Harb". input:"Harb"andsession_token:Ais sent in a new request.- A new list of predictions and their
place_ids are generated and returned - The user selects one of the predictions.
- The
place_idfor the selected prediction is sent to the Place Details service along withsession_token:A. - Place Details returns geographic details (locality name, lat/lng, etc.) for the selected place.
- A new session token is generated for any subsequent searches done by that user or any other users (i.e. DO NOT reuse session tokens).
Using session tokens in this way greatly minimizes billing costs incurred. Please see Google's session token documentation for more information.
Request structure for this service mirrors Google's request structure.
| Field | Type | Required | Example | Note |
|---|---|---|---|---|
input |
string |
True | "Harbi" |
|
session_token |
string |
True | - | Must be UUID. |
language |
string |
False | "et" |
See supported languages |
components |
array[string] |
False | ["US", "CA", "CN"] |
No more than 5 countries. Must be ISO 3166-1 Alpha-2 |
types |
string |
False | "(regions)" |
See place types |
Only required fields w/ a city:
{
"input": "Harbi",
"session_token": "<UUID_TOKEN>"
}Only required fields w/ a postal code:
{
"input": "90210",
"session_token": "<UUID_TOKEN>"
}Only required fields w/ a country:
{
"input": "China",
"session_token": "<UUID_TOKEN>"
}Only required fields w/ an address code:
{
"input": "1600 Pennsylvania Avenue, washington dc",
"session_token": "<UUID_TOKEN>"
}All fields:
{
"input": "Harbi",
"session_token": "<UUID_TOKEN>",
"language": "zh-cn",
"components": ["CN", "US", "CA", "ET", "FR"],
"types": "(regions)"
}The response contains a list of up to 5 predictions.
Each prediction contains:
descriptionstringplace_id- List of
termsand theiroffset - Location of the
matched_substringin the prediction result structured_formatting, pre-formatted text that can be used when displaying predictionsdistance_metersfromorigin(iforiginwas specified in the request)
Please see Google's documentation for additional information on these fields.
{
"data": {
"predictions": [
{
"description": "Harbin, 黑龙江省中国",
"place_id": "ChIJYRRkpvhkQ14R1SygWnOSfF4",
"types": [
"locality",
"political",
"geocode"
],
"terms": [
{
"offset": 0,
"value": "Harbin"
},
{
"offset": 8,
"value": "黑龙江省"
},
{
"offset": 12,
"value": "中国"
}
],
"structured_formatting": {
"main_text": "Harbin",
"secondary_text": "黑龙江省中国",
"main_text_matched_substrings": [
{
"length": 4,
"offset": 0
}
]
},
"matched_substring": [
{
"length": 4,
"offset": 0
}
],
"distance_meters": 5233
},
{
"description": "Nangang, 哈尔滨市黑龙江省中国",
"place_id": "ChIJIcgm1bB5RF4RZA29COpGXqg",
"types": [
"sublocality_level_1",
"sublocality",
"political",
"geocode"
],
"terms": [
{
"offset": 0,
"value": "Nangang"
},
{
"offset": 9,
"value": "哈尔滨市"
},
{
"offset": 13,
"value": "黑龙江省"
},
{
"offset": 17,
"value": "中国"
}
],
"structured_formatting": {
"main_text": "Nangang",
"secondary_text": "哈尔滨市黑龙江省中国",
"main_text_matched_substrings": [
{
"length": 7,
"offset": 0
}
]
},
"matched_substring": [
{
"length": 7,
"offset": 0
}
],
"distance_meters": 8416
}
]
}
}In the above example, the place_id value in the response could then be sent to Place Details to retrieve relevant geo information about this locality. Please see the request and response sections of Place Details documentation, which continue the above example and show this locations place information.
The current version of the service is 1.0.
Version must be specified in the Accept header. E.g. application/json;version=1.0.
Our general versioning strategy is available here.