迁移到附近搜索(新)
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
简介
Places API 支持附近搜索(旧版)。如果您熟悉“附近搜索”(旧版),那么
附近搜索(新)会做出以下更改:
- 附近搜索(新)使用 HTTP POST 请求。
在 HTTP POST 请求中,在请求正文或标头中传递参数。相比之下,使用“附近搜索”(旧版)时,您需要使用 HTTP GET 请求传递网址参数。
- 必须进行字段遮盖。您必须指定要在响应中返回哪些字段。没有默认的返回字段列表。如果您省略此列表,这些方法会返回错误。如需了解详情,请参阅 FieldMask。
- Nearby Search(新)支持使用 API 密钥和 OAuth 令牌作为身份验证机制。
- 在附近搜索(新)中,仅支持 JSON 作为响应格式。
- 现在,所有包含文本查询的请求都应使用文本搜索(新),因为附近搜索(新)不支持文本输入。
- 附近搜索(新)的 JSON 响应格式已从旧版 API 的格式更改为新格式。如需了解详情,请参阅迁移 Places API 响应。
下表列出了附近搜索(旧版)中已重命名或修改为附近搜索(新版)的参数,以及不再支持的参数。
当前形参 |
新增参数 |
备注 |
keyword |
|
不受支持。请改用新版文本搜索。 |
language |
languageCode |
|
location |
locationRestriction |
必需。 |
maxprice/minprice |
|
不受支持。 |
|
maxResultCount |
新参数。 |
opennow |
|
不受支持。 |
pagetoken |
|
不受支持。 |
radius |
|
立即使用 locationRestriction 。 |
rankby |
rankPreference |
|
|
regionCode |
新参数。 |
type |
includedTypes
excludedTypes
includedPrimaryTypes
excludedPrimaryTypes
|
新参数还接受多种类型的值。旧版 API 仅接受单个值。 |
示例请求
以下示例 GET 请求使用附近搜索(旧版)。在此示例中,您请求包含类型为 restaurant
的地点信息的 JSON 响应,并将所有参数作为网址参数传递:
curl -L -X GET \
'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=37.7937%2C-122.3965&radius=500&type=restaurant&key=API_KEY'
使用“附近搜索”(新)时,您需要发出 POST 请求,并在 JSON 请求正文或标头中传递所有参数,作为 POST 请求的一部分。此示例还使用了字段掩码,因此响应仅包含地点的显示名称和设有格式的地址:
curl -X POST -d '{
"includedTypes": ["restaurant"],
"locationRestriction": {
"circle": {
"center": {
"latitude": 37.7937,
"longitude": -122.3965},
"radius": 500.0
}
}
}' \
-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:searchNearby
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[],[],null,["# Migrate to Nearby 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 supports\n[Nearby Search (Legacy)](/maps/documentation/places/web-service/search-nearby).\nIf you are familiar with Nearby Search (Legacy), the [Nearby Search (New)](/maps/documentation/places/web-service/nearby-search) makes the following\nchanges:\n\n- Nearby 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 Nearby 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/nearby-search#fieldmask).\n- Nearby Search (New) supports both [API keys](/maps/documentation/places/web-service/get-api-key) and [OAuth](/maps/documentation/places/web-service/oauth-token) tokens as the authentication mechanism.\n- Only JSON is supported as a response format in Nearby Search (New).\n- All requests that include a text query should now use [Text Search (New)](/maps/documentation/places/web-service/text-search) because Nearby Search (New) does not support text input.\n- The JSON response format for Nearby 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 Nearby Search (Legacy) that have been\nrenamed or modified for Nearby Search (New), or parameters that are no\nlonger supported.\n\n| Current parameter | New parameter | Notes |\n|---------------------|-------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|\n| `keyword` | | Not supported. Use [Text Search (New)](/maps/documentation/places/web-service/text-search) instead. |\n| `language` | `languageCode` | |\n| `location` | `locationRestriction` | Required. |\n| `maxprice/minprice` | | Not supported. |\n| | `maxResultCount` | New parameter. |\n| `opennow` | | Not supported. |\n| `pagetoken` | | Not supported. |\n| `radius` | | Use `locationRestriction` now. |\n| `rankby` | `rankPreference` | |\n| | `regionCode` | New parameter. |\n| `type` | `includedTypes` `excludedTypes` `includedPrimaryTypes` `excludedPrimaryTypes` | The new parameters also accept multiple type values. The legacy API only accepts a single value. |\n\nExample request\n---------------\n\nThe following example GET request uses the Nearby Search (Legacy). In this\nexample, you request a JSON response containing information about places of type\n`restaurant` and pass all parameters as URL parameters: \n\n```curl\ncurl -L -X GET \\\n'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=37.7937%2C-122.3965&radius=500&type=restaurant&key=API_KEY'\n```\n\nWith Nearby Search (New), you make a POST request and pass all\nparameters in the JSON request body or in headers as part of the POST request.\nThis example also uses a field mask so the response only includes the display\nname and formatted address of the place: \n\n```curl\ncurl -X POST -d '{\n \"includedTypes\": [\"restaurant\"],\n \"locationRestriction\": {\n \"circle\": {\n \"center\": {\n \"latitude\": 37.7937,\n \"longitude\": -122.3965},\n \"radius\": 500.0\n }\n }\n}' \\\n-H 'Content-Type: application/json' -H \"X-Goog-Api-Key: API_KEY\" \\\n-H \"X-Goog-FieldMask: places.displayName,places.formattedAddress\" \\\nhttps://places.googleapis.com/v1/places:searchNearby\n```"]]