迁移到文本搜索(新)
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
简介
Places API(旧版)支持文本搜索(旧版)。如果您熟悉文本搜索(旧版),文本搜索(新)会进行以下更改:
- Text Search(新)使用 HTTP POST 请求。在 HTTP POST 请求中,在请求正文或标头中传递参数。
相比之下,使用文本搜索(旧版)时,您需要使用 HTTP GET 请求传递网址参数。
- 必须进行字段遮盖。您必须指定要在响应中返回哪些字段。没有默认的返回字段列表。如果您省略此列表,这些方法会返回错误。如需了解详情,请参阅 FieldMask。
- 文本搜索(新)支持使用 API 密钥和 OAuth 令牌作为身份验证机制。
- 在文本搜索(新)中,仅支持 JSON 作为响应格式。
借助文本搜索(旧版),您可以在查询字符串中指定纬度和经度坐标。例如:query=37.4239,-122.0925
。
文本搜索(新)不支持该选项。
使用反向地理编码按坐标进行搜索并返回地址,或使用附近搜索(新)查找特定位置附近的地点。
- 文本搜索(新)的 JSON 响应格式已从旧版 API 的格式更改为新格式。如需了解详情,请参阅迁移 Places API 响应。
下表列出了在文本搜索(旧版)中已重命名或修改为文本搜索(新版)的参数,以及不再支持的参数。
当前形参 |
新增参数 |
备注 |
|
evOptions |
新参数。 |
language |
languageCode |
|
location |
locationBias |
|
maxprice/minprice |
priceLevels |
|
opennow |
openNow |
|
pagetoken |
pageToken |
|
query |
textQuery |
所有请求中都必须包含此字段。 |
radius |
locationBias |
定义 locationBias 时,请指定半径。 |
region |
regionCode |
|
type |
includedType |
仅接受单个值。 |
|
strictTypeFiltering |
新参数。 |
示例请求
以下示例 GET 请求使用文本搜索(旧版)。在此示例中,您请求包含“澳大利亚悉尼的辣味素食”相关信息的 JSON 响应,并将所有参数作为网址参数传递:
curl -L -X GET \
'https://maps.googleapis.com/maps/api/place/textsearch/json?query=Spicy%20Vegetarian%20Food%20in%20Sydney%20Australia&key=API_KEY
使用文本搜索(新)时,您需要发出 POST 请求,并在 JSON 请求正文中或标头中传递所有参数,作为 POST 请求的一部分。此示例还使用了字段掩码,因此响应仅包含地点的显示名称和格式化地址:
curl -X POST -d '{
"textQuery" : "Spicy Vegetarian Food in Sydney, Australia"
}' \
-H 'Content-Type: application/json' -H 'X-Goog-Api-Key: API_KEY' \
-H 'X-Goog-FieldMask: places.displayName,places.formattedAddress' \
'https://places.googleapis.com/v1/places:searchText'
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[],[],null,["# Migrate to Text Search (New)\n\n**European Economic Area (EEA) developers** If your billing address is in the European Economic Area, effective on 8 July 2025, the [Google Maps Platform EEA Terms of Service](https://cloud.google.com/terms/maps-platform/eea) will apply to your use of the Services. Functionality varies by region. [Learn more](/maps/comms/eea/faq).\n\nIntroduction\n------------\n\nPlaces API (Legacy) supports\n[Text Search (Legacy)](/maps/documentation/places/web-service/legacy/search-text). If you are familiar with\nText Search (Legacy),\n[Text Search (New)](/maps/documentation/places/web-service/text-search)\nmakes the following changes:\n\n- Text Search (New) uses HTTP POST requests. Pass parameters in the request body or in headers as part of an HTTP POST request. In contrast, with Text Search (Legacy), you pass URL parameters using an HTTP GET request.\n- Field masking is required. You must specify which fields you want returned in the response. There is no default list of returned fields. If you omit this list, the methods return an error. For more information, see [FieldMask](/maps/documentation/places/web-service/text-search#fieldmask).\n- Text Search (New) supports both [API keys](/maps/documentation/places/web-service/legacy/get-api-key) and [OAuth](/maps/documentation/places/web-service/legacy/oauth-token) tokens as the authentication mechanism.\n- Only JSON is supported as a response format in Text Search (New).\n- Text Search (Legacy) lets you specify latitude and longitude\n coordinates in the query string. For example: `query=37.4239,-122.0925`.\n That option is not supported in Text Search (New).\n\n Use\n [Reverse Geocoding](/maps/documentation/geocoding/requests-reverse-geocoding)\n to search on coordinates and return an address, or\n [Nearby Search (New)](/maps/documentation/places/web-service/nearby-search)\n to find places around a certain location.\n- The JSON response format for Text Search (New) has changed from the format of the legacy APIs. For more details, see [Migrate the Places API response](/maps/documentation/places/web-service/migrate-response).\n\nThe following table lists parameters in Text Search (Legacy) that have been\nrenamed or modified for Text Search (New), or parameters that are no\nlonger supported.\n\n| Current parameter | New parameter | Notes |\n|---------------------|-----------------------|----------------------------------------------------|\n| | `evOptions` | New parameter. |\n| `language` | `languageCode` | |\n| `location` | `locationBias` | |\n| `maxprice/minprice` | `priceLevels` | |\n| `opennow` | `openNow` | |\n| `pagetoken` | `pageToken` | |\n| `query` | `textQuery` | Required in all requests. |\n| `radius` | `locationBias` | Specify the radius when defining a `locationBias`. |\n| `region` | `regionCode` | |\n| `type` | `includedType` | Only takes a single value. |\n| | `strictTypeFiltering` | New parameter. |\n\nExample request\n---------------\n\nThe following example GET request uses Text Search (Legacy). In this example, you\nrequest a JSON response containing information about \"Spicy Vegetarian Food in\nSydney, Australia\" and pass all parameters as URL parameters: \n\n```curl\ncurl -L -X GET \\\n'https://maps.googleapis.com/maps/api/place/textsearch/json?query=Spicy%20Vegetarian%20Food%20in%20Sydney%20Australia&key=API_KEY\n```\n\nWith Text Search (New), you make a POST request and pass all parameters in\nthe JSON request body or in headers as part of the POST request. This example\nalso uses a field mask so the response only includes the display name and\nformatted address of the place: \n\n```\ncurl -X POST -d '{\n \"textQuery\" : \"Spicy Vegetarian Food in Sydney, Australia\"\n}' \\\n-H 'Content-Type: application/json' -H 'X-Goog-Api-Key: API_KEY' \\\n-H 'X-Goog-FieldMask: places.displayName,places.formattedAddress' \\\n'https://places.googleapis.com/v1/places:searchText'\n```"]]