Google Maps Platform API的申請與使用

關於API使用的費用與支出
瞭解Google的收費標準
API的使用上費用當然是很重要的關鍵,否則除非是大量的資料擷取使用或是有什麼即時的需要,否則透過爬網頁的方式,我試過用Python也是能達到同樣的目的,但總之就是研究一下囉。 如果使用Google Maps Platform的API,收費採即付即用的計費方式,用多少就付多少,且其實每個月會提供 $200 美元的抵免額來折抵費用。所以使用上就是查詢量控制好壓在那個限制下即可,而查詢量又可以透過設定用量限制的方式,避免出現預算超支的意外情況。關於設定用量限制的部份,紀錄在這篇文章的最後一段。 從Google官方的「Google Maps Platform地圖介面集定價表」,可以一目了然的知道各介面集的收費標準。監看API的使用量
透過「Google API Console」就可以直接看到目前API使用概況。同時可以切換各個取樣週期,查詢起來算是非常的直觀、明瞭。
API Key的申請
到「Google Cloud Platform / API和服務 / 憑證」申請憑證



使用Google Maps Platform API來進行查詢
在GMP Documentation上找到完整的參考資訊
透過以下的「Google Maps Platform Documentation」連結,找尋你需要的API說明文件。以我為例,我需要的是 Places API 下的 Place Details 介面。- Maps
- Routes
- Places
- Places SDK for Android
- Places SDK for iOS
- Places Library, Map JavaScript API
- Places API
- Place Search
- Place Details
- Place Photos
- Place Autocomplete
- Query Autocomplete
- Geocoding API
- Geolocation API
- Time Zone API
- Industry Solutions
https://maps.googleapis.com/maps/api/place/details/output?parameters關於details後的 output 與 parameters,說明如下 output會有兩個值,分別為:
- json
- xml
- key(必要)
- place_id(必要)
- language(非必要)
- region(非必要)
- sessiontoken(非必要)
- fields(非必要)
fields指的就是要取得哪些關於這個店家的資料欄位。
- 如果要知道總共有哪些欄位
- 要注意的是,目前
permanently_closed
這個欄位已經被取消,同時被歸納至business_status
這個欄位中的狀態別。
開始透過API進行查詢
完成以上的API Key申請後,馬上就可以使用它來進行查詢。https://maps.googleapis.com/maps/api/place/details/json?place_id=ChIJuaevwBioQjQRYxPlADKSd5U&key=申請的API_Key

https://maps.googleapis.com/maps/api/place/details/json?place_id=ChIJuaevwBioQjQRYxPlADKSd5U&fields=name,rating,user_ratings_total&key=申請的API_Key至於怎麼知道這些欄位名稱的?其實可以參考上面沒有加入fields參數時回應的JSON字串,再對照Google Map上的網頁就概略可以推知了。
如何設定用量限制
設定的步驟如下:




監看特定API的詳細報表
步驟如下:


