遷移至 Text Search (新功能)
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
簡介
Places API (舊版) 支援文字搜尋 (舊版)。如果您熟悉 Text Search (舊版),Text Search (新版) 會進行下列變更:
- Text Search (New) 使用 HTTP POST 要求。在要求主體或標頭中傳遞參數,做為 HTTP POST 要求的一部分。相較之下,使用 Text Search (舊版) 時,您會透過 HTTP GET 要求傳遞網址參數。
- 必須遮蓋欄位。您必須指定要在回應中傳回的欄位。系統不會預設傳回任何欄位。如果省略這份清單,方法會傳回錯誤。詳情請參閱 FieldMask。
- Text Search (新版) 支援 API 金鑰和 OAuth 權杖做為驗證機制。
- 在「文字搜尋 (新版)」中,僅支援 JSON 做為回應格式。
使用「文字搜尋 (舊版)」時,您可以在查詢字串中指定經緯度座標。例如:query=37.4239,-122.0925
。
文字搜尋 (新版) 不支援該選項。
使用反向地理編碼依座標搜尋並傳回地址,或使用Nearby Search (新版) 尋找特定位置周圍的地點。
- Text Search (New) 的 JSON 回應格式已從舊版 API 的格式變更。詳情請參閱「遷移 Places API 回應」。
下表列出 Text Search (舊版) 中已重新命名或修改的參數,以及 Text Search (新版) 不再支援的參數。
目前參數 |
新增參數 |
記事 |
|
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
使用 Text Search (新版) 時,您會發出 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'
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間: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```"]]