遷移至 Autocomplete (新推出)
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
簡介
Places API 支援地點自動完成 (舊版) 和查詢自動完成 (舊版) API。如果您熟悉這些 API,Autocomplete (New) 會進行下列變更:
- Autocomplete (新版) 使用 HTTP POST 要求。在要求主體或標頭中傳遞參數,做為 HTTP POST 要求的一部分。相較之下,使用舊版 API 時,您會透過 HTTP GET 要求傳遞網址參數。
- 自動完成 (新版) 支援 API 金鑰和 OAuth 權杖做為驗證機制。
- 在「自動完成 (新版)」中,僅支援 JSON 做為回應格式。
下表列出 Autocomplete (新版) 中已重新命名或修改的 Place Autocomplete (舊版) 和 Query Autocomplete (舊版) 參數,以及不再支援的參數。
目前參數 |
新增參數 |
記事 |
components |
includedRegionCodes |
|
language |
languageCode |
|
location |
locationBias |
|
ipbias |
|
如果省略 locationBias 和 locationRestriction ,API 預設會使用 IP 偏誤。 |
offset |
inputOffset |
|
radius |
locationBias 或 locationRestriction |
|
region |
regionCode |
|
stricbounds |
locationRestriction |
|
sessiontoken |
sessionToken |
|
types |
includedPrimaryTypes |
|
要求範例
下列範例 GET 要求使用 Place Autocomplete (舊版)。在本範例中,您要求 JSON 回應包含名為「Amoeba」且類型為 establishment
的地點資訊,並將所有參數當做網址參數傳遞:
curl -L -X GET 'https://maps.googleapis.com/maps/api/place/autocomplete/json?input=amoeba&types=establishment&location=37.76999%2C-122.44696&radius=500&key=YOUR_API_KEY'
使用 Autocomplete (新版) 時,您會發出 POST 要求,並在 JSON 要求內文或標頭中傳遞所有參數,做為 POST 要求的一部分。
Autocomplete (New) 要求不需要欄位遮罩,但可用於篩選回應中的特定結果。舉例來說,下列要求使用欄位遮罩,因此回應只會包含建議的 suggestions.placePrediction.text
:
curl -X POST -d '{
"input": "Amoeba",
"locationBias": {
"circle": {
"center": {
"latitude": 37.76999,
"longitude": -122.44696
},
"radius": 500.0
}
}
}' \
-H 'Content-Type: application/json' -H 'X-Goog-Api-Key: API_KEY' \
-H 'X-Goog-FieldMask: suggestions.placePrediction.text' \
https://places.googleapis.com/v1/places:autocomplete
如要進一步瞭解如何使用欄位遮罩,請參閱「地點詳細資料 (新版)」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[],[],null,["# Migrate to Autocomplete (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 the\n[Place Autocomplete (Legacy)](/maps/documentation/places/web-service/autocomplete)\nand [Query Autocomplete (Legacy)](/maps/documentation/places/web-service/query) APIs.\nIf you are familiar with these APIs, Autocomplete (New) makes the following changes:\n\n- Autocomplete (New) uses HTTP POST requests. Pass parameters in the request body or in headers as part of an HTTP POST request. In contrast, with the legacy APIs, you pass URL parameters using an HTTP GET request.\n- Autocomplete (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 Autocomplete (New).\n\nThe following table lists parameters in Place Autocomplete (Legacy) and Query Autocomplete (Legacy) that have been renamed or modified for Autocomplete (New), or parameters that are no longer supported.\n\n| Current parameter | New parameter | Notes |\n|-------------------|-----------------------------------------|-----------------------------------------------------------------------------------------------------|\n| `components` | `includedRegionCodes` | |\n| `language` | `languageCode` | |\n| `location` | `locationBias` | |\n| `ipbias` | | If you omit both `locationBias` and `locationRestriction`, then the API uses IP biasing by default. |\n| `offset` | `inputOffset` | |\n| `radius` | `locationBias` or `locationRestriction` | |\n| `region` | `regionCode` | |\n| `stricbounds` | `locationRestriction` | |\n| `sessiontoken` | `sessionToken` | |\n| `types` | `includedPrimaryTypes` | |\n\nExample request\n---------------\n\nThe following example GET request uses Place Autocomplete (Legacy). In this\nexample, you request a JSON response containing information about places called\n\"Amoeba\" that are of type `establishment` and pass all parameters as URL\nparameters: \n\n```curl\ncurl -L -X GET 'https://maps.googleapis.com/maps/api/place/autocomplete/json?input=amoeba&types=establishment&location=37.76999%2C-122.44696&radius=500&key=YOUR_API_KEY'\n```\n\nWith Autocomplete (New), you make a POST request and pass all parameters\nin the JSON request body or in headers as part of the POST request.\n\nField masks are not required for Autocomplete (New) requests, but they can\nbe used to filter for specific results in the response. For example, the\nfollowing request uses a field mask so the response only includes the\n`suggestions.placePrediction.text` of the suggestion: \n\n```curl\ncurl -X POST -d '{\n \"input\": \"Amoeba\",\n \"locationBias\": {\n \"circle\": {\n \"center\": {\n \"latitude\": 37.76999,\n \"longitude\": -122.44696\n },\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: suggestions.placePrediction.text' \\\nhttps://places.googleapis.com/v1/places:autocomplete\n```\n\nTo learn more about using field masks, see\n[Place Details (New)](/maps/documentation/places/web-service/place-details#fieldmask)."]]