本文將逐步說明如何向 Places Aggregate API 提出基本要求,以及如何解讀回應 (包括相符地點的數量)。
如要使用 Places Aggregate API,請向 computeInsights 端點傳送 HTTP POST 要求,如下所示:
https://areainsights.googleapis.com/v1:computeInsights
在 JSON 主體中提供區域和類型參數,進一步調整要求。以下範例要求傳回舊金山營業中、價格適中且評分為 4 到 5 星的餐廳數量。
curl --location 'https://areainsights.googleapis.com/v1:computeInsights' \
--header 'X-Goog-Api-Key: API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"insights":[
"INSIGHT_COUNT"
],
"filter":{
"locationFilter":{
"region":{
"place":"places/ChIJIQBpAG2ahYAR_6128GcTUEo"
}
},
"typeFilter":{
"includedTypes":[
"restaurant"
]
},
"operatingStatus":[
"OPERATING_STATUS_OPERATIONAL"
],
"priceLevels":[
"PRICE_LEVEL_INEXPENSIVE"
],
"ratingFilter":{
"minRating":4.0,
"maxRating":5.0
}
}
}'
Places Aggregate API 回應
以下是上述範例要求的回應,顯示符合條件的餐廳數量。
{ "count": "850" }
試試看!
API Explorer 可讓您提出範例要求,熟悉 API 和 API 選項。
- 選取頁面右側的 API 圖示
。 - 視需要展開「Show standard parameters」(顯示標準參數),設定任何參數。
- 視需要編輯「Request body」(要求主體)。
- 選取「Execute」按鈕。在對話方塊中,選擇要用來提出要求的帳戶。
在 API Explorer 面板中,選取展開圖示
,展開 API Explorer 視窗。