Google Places API

PythonでGooglePlacesAPIを利用してみる。

from googleplaces import GooglePlaces, types, lang, json

YOUR_API_KEY   = 'AIzaSyDMiOg7qvttHyeAarDLX2Mxacmrr3soqD4'
google_places  = GooglePlaces(YOUR_API_KEY)

# You may prefer to use the text_search API, instead.
query_result = google_places.nearby_search(
    language   = 'ja',
    location   = '東京, 日本',
    # keyword  = '青百合',
    # radius   = 20000,
    types      = 'food | cafe | bar'
)

if query_result.has_attributions:
    print(query_result.has_attributions)
for place in query_result.places:
    line = []
    geo_name = ''
    location = ''
    tel = ''

    place.get_details()

    # プレイス名称
    geo_name = place.name
    if geo_name == None :
        line.append('NULL')
    else :
        line.append(geo_name)

    # 緯度経度
    location = place.geo_location
    lat = str(location["lat"])
    lng = str(location["lng"])

    if lat == None :
        line.append('NULL')
    else :
        line.append(lat)

    if lng == None :
        line.append('NULL')
    else :
        line.append(lng)

    # 電話番号
    tel = place.local_phone_number
    if tel == None :
        line.append('NULL')
    else :
        line.append(tel)

    print(line)

▼ 出力結果

/Users/xxx/.pyenv/versions/3.4.5/bin/python "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 52233 --file /Users/xxx/Dropbox/Sites/pythonTest/googlePlacesApi.py
warning: Debugger speedups using cython not found. Run '"/Users/aaa/.pyenv/versions/3.4.5/bin/python" "/Applications/PyCharm CE.app/Contents/helpers/pydev/setup_cython.py" build_ext --inplace' to build.
pydev debugger: process 38426 is connecting

Connected to pydev debugger (build 163.9735.8)
['東京', {'lat': Decimal('35.7090259'), 'lng': Decimal('139.7319925')}, None]
['ホテル椿山荘東京', {'lat': Decimal('35.7121974'), 'lng': Decimal('139.726076')}, '03-3943-1111']
['ホテルグランドパレス', {'lat': Decimal('35.6973265'), 'lng': Decimal('139.7504322')}, '03-3264-1111']
['庭のホテル東京', {'lat': Decimal('35.700622'), 'lng': Decimal('139.75667')}, '03-3293-0028']
['Hotel Higashi-Shinjuku イーホテル東新宿', {'lat': Decimal('35.6977609'), 'lng': Decimal('139.7071375')}, '03-5287-3588']
['ホテルリステル新宿', {'lat': Decimal('35.692872'), 'lng': Decimal('139.711396')}, '03-3350-0123']
['Citadines Shinjuku Tokyo', {'lat': Decimal('35.6910489'), 'lng': Decimal('139.7131214')}, '03-5379-7208']
['東急ステイ水道橋', {'lat': Decimal('35.70081589999999'), 'lng': Decimal('139.7565031')}, '03-3293-0109']
['エースイン新宿', {'lat': Decimal('35.6925119'), 'lng': Decimal('139.7243036')}, '03-3350-6655']
['東横INN新宿歌舞伎町', {'lat': Decimal('35.69732310000001'), 'lng': Decimal('139.7043361')}, '03-5155-1045']
['ホテル機山館', {'lat': Decimal('35.7080429'), 'lng': Decimal('139.7597332')}, '03-3812-1211']
['シタディーンセントラル新宿東京', {'lat': Decimal('35.6944294'), 'lng': Decimal('139.7042888')}, '03-3200-0220']
['ホテルたてしな', {'lat': Decimal('35.692288'), 'lng': Decimal('139.709014')}, '03-3350-5271']
['ホテルメトロポリタン', {'lat': Decimal('35.7283502'), 'lng': Decimal('139.7079847')}, '03-3980-1111']
['ホテルシェーナ', {'lat': Decimal('35.69599540000001'), 'lng': Decimal('139.704277')}, '03-3232-6711']
['YMCAアジア青少年センター', {'lat': Decimal('35.7000021'), 'lng': Decimal('139.7585113')}, '03-3233-0611']
['新宿区', {'lat': Decimal('35.6938401'), 'lng': Decimal('139.7035494')}, None]

Process finished with exit code 0