Skip to content

Instantly share code, notes, and snippets.

@hehehaha0228

hehehaha0228/getPhoto.py

Last active Nov 11, 2020
Embed
What would you like to do?
import googlemaps
import os
google_key = "AIzaSyCLfZQjoR4uuH3-gikZOf01XLltl_bSlxx"
gmaps = googlemaps.Client(key = google_key)
#前面一樣要先取得google key,還有設定client
#下面這邊,我假設妳已經取得了10個photo_reference,並且將他們存在list裡面
n = 0
for storePhoto_reference in storePhoto_references:
try:
photo = gmaps.places_photo(photo_reference = storePhoto_reference, max_width=800, max_height=800)
#這邊參數一個當然是傳如photo_reference,另外也可以設定最大高度和寬度,最大都為1600,依照你的需求設定。
f = open(str(n) + ".png", "wb")
#這邊我設定了我的檔案名稱還有存取的方式,因為圖片檔案是二進位檔案,所以用"wb"
for chunk in photo:
if chunk:
f.write(chunk)
f.close()
n = n+1
except:
print(fileName + "failed")
continue
print(storeName + "結束")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment