我在Python中使用Google Place API进行 Web服务。 我正在尝试添加the tutorial here
等地点我的代码在这里:
function main(sources: ISources): ISinks {
const dom = sources.dom;
const resetClick$ = dom.select("#resetButton")
.events("click")
.map(ev => 0)
.startWith(0)
const button1Click$ = dom.select("#button1")
.events("click")
.compose(dropUntil(resetClick$.last()))
.map(ev => 1)
.fold((acc, n) => acc + n, 0)
.startWith(0)
const button2Click$ = dom.select("#button2")
.events("click")
.compose(dropUntil(resetClick$.last()))
.map(ev => 1)
.fold((acc, n) => acc + n, 0)
.startWith(0)
const vtree$ = Stream.combine(button1Click$, button2Click$)
.map(n =>
div([
input("#button1", { attrs: { type: "button", value: "Click Me!"}}),
input("#button2", { attrs: { type: "button", value: "Click Me!"}}),
input("#resetButton", { attrs: { type: "button", value: "Reset!"}}),
p(["Clicks: " + n[0] + " + " + n[1]]),
p(["Click total: " + (n[0] + n[1])])
])
)
const sinks: ISinks = {
dom: vtree$
};
return sinks;
}
我尝试将输入更改为Json格式或Python字典格式,然后它给出了错误“google_places.add_place()只接受1个参数,2个给出”......
有没有正确的方法在Python中使用Google Place API 添加地方法?
答案 0 :(得分:0)
哦,最后我找到了解决方案,它非常简单......我不熟悉Python POST请求,事实上一切都很简单。
只需要这里的代码,我们就可以使用Python在Google Place API中添加一个地方:
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()