使用Python在Google Maps API中查找附近餐厅的网站。

huangapple go评论71阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年6月8日 20:45:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76431988.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定