如何使用Google Place在Python中添加

如何使用Google Place在Python中添加

问题描述:

我在Python中使用Google Place API for Web Service。 和我想要添加的地方,如the tutorial here如何使用Google Place在Python中添加

我的代码如下:

from googleplaces import GooglePlaces, types, lang, GooglePlacesError, GooglePlacesAttributeError 

API_KEY = "[Google Place API KEY]" 
google_places = GooglePlaces(API_KEY) 

try: 
    added_place = google_places.add_place(
     name='Mom and Pop local store', 
     lat_lng={'lat': 51.501984, 'lng': -0.141792}, 
     accuracy=100, 
     types=types.TYPE_HOME_GOODS_STORE, 
     language=lang.ENGLISH_GREAT_BRITAIN) 

except GooglePlacesError as error_detail: 
    print error_detail 

但我一直收到此错误: error

我试图改变输入JSON格式或Python字典格式,然后它给了错误“google_places.add_place()只接受1参数,2给”......

是否有任何正确的方式来使用Google Place API 在Python中添加地方法

哦,终于找到了解决方案,它非常简单......我不熟悉Python POST请求,事实上一切都很简单。

只需要代码在这里,我们将能够添加一个地方在谷歌广场API,与Python:

import requests 

post_url = "https://maps.googleapis.com/maps/api/place/add/json?key=" + [YOUR_API_KEY] 

r = requests.post(post_url, json={ 
    "location": { 
    "lat": -33.8669710, 
    "lng": 151.1958750 
    }, 
    "accuracy": 50, 
    "name": "Google Shoes!", 
    "phone_number": "(02) 9374 4000", 
    "address": "48 Pirrama Road, Pyrmont, NSW 2009, Australia", 
    "types": ["shoe_store"], 
    "website": "http://www.google.com.au/", 
    "language": "en-AU" 
}) 

检查结果:

print r.status_code 
print r.json()