AutocompleteService 类
google.maps.places.AutocompleteService
类
包含与检索自动补全预测结果相关的方法。
通过调用 const {AutocompleteService} = await google.maps.importLibrary("places")
进行访问。
请参阅 Maps JavaScript API 中的库。
构造函数 | |
---|---|
AutocompleteService |
AutocompleteService() 参数:无
创建 AutocompleteService 的新实例。 |
方法 | |
---|---|
getPlacePredictions |
getPlacePredictions(request[, callback]) 参数:
返回值:
Promise<AutocompleteResponse> 根据提供的自动补全请求检索地点自动补全预测结果。 |
getQueryPredictions |
getQueryPredictions(request, callback) 参数:
返回值:无
根据提供的查询自动补全请求检索查询自动补全联想查询。 |
AutocompletionRequest 接口
google.maps.places.AutocompletionRequest
接口
要发送到 AutocompleteService.getPlacePredictions
的自动补全请求。
属性 | |
---|---|
input |
类型:
string 用户输入的字符串。 |
|
类型:
LatLngBounds|LatLngBoundsLiteral optional 预测偏差的界限。预测结果会偏向于(但不限于)给定的 bounds 。如果设置了 bounds ,系统会忽略 location 和 radius 。 |
componentRestrictions optional |
类型:
ComponentRestrictions optional 组件限制。组件限制用于将预测限制为仅在父组件内进行。例如,国家/地区。 |
language optional |
类型:
string optional 一种语言标识符,用于指定结果应以哪种语言返回(如果可能)。系统可能会优先显示所选语言的结果,但建议不限于此语言。请参阅支持的语言列表。 |
|
类型:
LatLng optional 用于预测偏差调整的位置。预测结果将偏向给定的 location 和 radius 。或者,您也可以使用 bounds 。 |
locationBias optional |
类型:
LocationBias optional 搜索地点时使用的软边界或提示。 |
locationRestriction optional |
类型:
LocationRestriction optional 用于限制搜索结果的边界。 |
offset optional |
类型:
number optional 输入字词中服务使用文本进行预测的字符位置(输入字段中光标的位置)。 |
origin optional |
类型:
LatLng|LatLngLiteral optional 计算 AutocompletePrediction.distance_meters 所用的位置。 |
|
类型:
number optional 用于预测偏差调整的区域的半径。 radius 以米为单位指定,并且必须始终与 location 属性一起使用。或者,您也可以使用 bounds 。 |
region optional |
类型:
string optional 用于设置结果格式和过滤结果的地区代码。它不会将建议限制在此国家/地区。地区代码接受 ccTLD(“顶级域名”)双字符值。多数 ccTLD 代码都与 ISO 3166-1 代码相同,但也有一些需要注意的例外情况。例如,英国的 ccTLD 为“uk”( .co.uk ),而其 ISO 3166-1 代码为“gb”(从技术上讲,是指“大不列颠及北爱尔兰联合王国”这一实体)。 |
sessionToken optional |
类型:
AutocompleteSessionToken optional 用于将各个请求捆绑到会话中的唯一引用。 |
types optional |
类型:
Array<string> optional 要返回的预测类型。如需了解支持的类型,请参阅 开发者指南。如果未指定任何类型,系统将返回所有类型。 |
AutocompleteResponse 接口
google.maps.places.AutocompleteResponse
接口
对 AutocompleteService.getPlacePredictions
的调用返回的自动补全响应,其中包含 AutocompletePrediction
的列表。
属性 | |
---|---|
predictions |
QueryAutocompletionRequest 接口
google.maps.places.QueryAutocompletionRequest
接口
要发送到 QueryAutocompleteService
的 QueryAutocompletion 请求。
属性 | |
---|---|
input |
类型:
string 用户输入的字符串。 |
bounds optional |
类型:
LatLngBounds|LatLngBoundsLiteral optional 预测偏差的界限。预测结果会偏向于(但不限于)给定的 bounds 。如果设置了 bounds ,系统会忽略 location 和 radius 。 |
location optional |
类型:
LatLng optional 用于预测偏差调整的位置。预测结果将偏向给定的 location 和 radius 。或者,您也可以使用 bounds 。 |
offset optional |
类型:
number optional 输入字词中服务使用文本进行预测的字符位置(输入字段中光标的位置)。 |
radius optional |
类型:
number optional 用于预测偏差调整的区域的半径。 radius 以米为单位指定,并且必须始终与 location 属性一起使用。或者,您也可以使用 bounds 。 |
ComponentRestrictions 接口
google.maps.places.ComponentRestrictions
接口
定义可用于自动补全服务的组件限制。
属性 | |
---|---|
country optional |
类型:
string|Array<string> optional 将预测结果限制在指定国家/地区内(ISO 3166-1 Alpha-2 国家/地区代码,不区分大小写)。例如 'us' 、'br' 或 'au' 。您可以提供一个国家/地区代码字符串,也可以提供一个包含最多五个国家/地区代码字符串的数组。 |
AutocompletePrediction 接口
google.maps.places.AutocompletePrediction
接口
表示单个自动补全预测结果。
属性 | |
---|---|
description |
类型:
string 这是由 Places 服务建议的未格式化的查询。 |
matched_substrings |
类型:
Array<PredictionSubstring> 地点说明中的一组子字符串,这些子字符串与用户输入中的元素相匹配,适合用于突出显示这些子字符串。每个子字符串都由一个偏移量和一个长度(以 Unicode 字符表示)标识。 |
place_id |
类型:
string 一个地点 ID,可用于通过地点详情服务检索相应地点的详细信息(请参阅 PlacesService.getDetails )。 |
structured_formatting |
有关地点描述的结构化信息,分为主要文本和辅助文本,包括来自自动补全输入的匹配子字符串数组,由偏移量和长度(以 Unicode 字符表示)标识。 |
terms |
类型:
Array<PredictionTerm> 上述说明中各个术语的相关信息,从最具体到最不具体。例如,“Taco Bell”“Willits”和“CA”。 |
types |
类型:
Array<string> 预测所属的类型数组,例如 'establishment' 或 'geocode' 。 |
distance_meters optional |
类型:
number optional 相应地点与 AutocompletionRequest.origin 之间的距离(以米为单位)。 |
QueryAutocompletePrediction 接口
google.maps.places.QueryAutocompletePrediction
接口
表示单个查询自动补全预测结果。
属性 | |
---|---|
description |
类型:
string 这是由 Places 服务建议的未格式化的查询。 |
matched_substrings |
类型:
Array<PredictionSubstring> 地点说明中的一组子字符串,这些子字符串与用户输入中的元素相匹配,适合用于突出显示这些子字符串。每个子字符串都由一个偏移量和一个长度(以 Unicode 字符表示)标识。 |
terms |
类型:
Array<PredictionTerm> 有关上述说明中各个术语的信息。类别字词在前(例如“餐厅”)。地址字词按从最具体到最不具体的顺序显示。例如,“旧金山”和“加利福尼亚州”。 |
place_id optional |
类型:
string optional 仅当预测结果为地点时才可用。一个地点 ID,可用于通过地点详情服务检索相应地点的详细信息(请参阅 PlacesService.getDetails )。 |
PredictionTerm 接口
google.maps.places.PredictionTerm
接口
表示预测字词。
属性 | |
---|---|
offset |
类型:
number 相应字词在地点说明中的起始位置(以 Unicode 字符为单位)。 |
value |
类型:
string 相应搜索字词的值,例如“Taco Bell”。 |
PredictionSubstring 接口
google.maps.places.PredictionSubstring
接口
表示预测子字符串。
属性 | |
---|---|
length |
类型:
number 子字符串的长度。 |
offset |
类型:
number 子字符串在说明字符串中的起始偏移量。 |
StructuredFormatting 接口
google.maps.places.StructuredFormatting
接口
包含有关地点描述的结构化信息,分为主要文本和辅助文本,包括来自自动补全输入的匹配子字符串数组,由偏移量和长度(以 Unicode 字符表示)标识。
属性 | |
---|---|
main_text |
类型:
string 这是由 Places 服务建议的未格式化地点描述的主要文本部分。通常是地点的名称。 |
main_text_matched_substrings |
类型:
Array<PredictionSubstring> 主文本中的一组子字符串,这些子字符串与用户输入中的元素相匹配,适合用于突出显示这些子字符串。每个子字符串都由一个偏移量和一个长度(以 Unicode 字符表示)标识。 |
secondary_text |
类型:
string 这是由 Places 服务建议的未格式化地点说明的辅助文本部分。通常是相应地点的地理位置。 |