英文:
Find websites of nearby restaurants in GoogleMaps API using Python
问题
以下是找到伦敦特拉法加广场附近餐厅的代码:
import googlemaps
gmaps = googlemaps.Client(key='API_KEY')
# 地址地理编码
geocode_result = gmaps.geocode('Trafalgar Square, London, United Kingdom')
# 查找附近的地点
places_result = gmaps.places_nearby(location=geocode_result[0]['geometry']['location'], radius=500, type='restaurant')
for place in places_result['results']:
print(place['name'])
然而,我想获取它们的网站,但我没有找到任何名为 place['website']
的字段?
英文:
The following code finds restaurants near Trafalgar Square in London:
import googlemaps
gmaps = googlemaps.Client(key='API_KEY')
# Geocoding an address
geocode_result = gmaps.geocode('Trafalgar Square, London, United Kingdom')
# Look up nearby places
places_result = gmaps.places_nearby(location=geocode_result[0]['geometry']['location'], radius=500, type='restaurant')
for place in places_result['results']:
print(place['name'])
However, I would like to get their websites, but I don't find any field such as place['website']
?
答案1
得分: 0
根据您使用的终端点,每个结果都将带有一个place_id
参数。使用这个place_id
,您可以访问地点详细信息终端点。
URL看起来像这样,并且根据我在文档中看到的信息,将包含一个网站字段。
https://maps.googleapis.com/maps/api/place/details/json?place_id=ChIJi6C1MxquEmsR9-c-3O48ykI
英文:
Looking at the endpoint you used each result will come with a place_id
parameter. Using this place_id
you can hit the place details endpoint
The URL looks like this and from what I've seen in the documentation there will be a website field included.
https://maps.googleapis.com/maps/api/place/details/json?place_id=ChIJi6C1MxquEmsR9-c-3O48ykI
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论