【问题标题】:how to get place details from place id in google places api for python如何从 google places api for python 中的地点 id 获取地点详细信息
【发布时间】:2016-03-20 19:56:46
【问题描述】:

我正在使用带有 Python 的 Google Places API 来构建一个用于食物的集体智慧应用程序。例如附近有哪些餐馆,他们的评分是多少,他们的时间是什么等。

我在 Python 中执行以下操作:

from googleplaces import GooglePlaces, types, lang

API_KEY = ''

google_places = GooglePlaces(API_KEY)

query_result = google_places.nearby_search(
    location='Mumbai', keyword='Restaurants',
    radius=1000, types=[types.TYPE_RESTAURANT])

if query_result.has_attributions:
   print query_result.html_attributions


for place in query_result.places:
    print place.name
    print place.geo_location
    print place.place_id  

它返回给我的是这样的:

Subway
{u'lat': Decimal('19.1156005'), u'lng': Decimal('72.9090715')}
ChIJV2JWaObH5zsRt-FrEb8lrtM
Aroma's Cafe
{u'lat': Decimal('19.116867'), u'lng': Decimal('72.90982199999999')}
ChIJSWijB-bH5zsRVLE5ipsxvHU
Chili's
{u'lat': Decimal('19.1161942'), u'lng': Decimal('72.90909789999999')}
ChIJ4_2UcubH5zsRWMemt2WTsLc
Mainland China
{u'lat': Decimal('19.1154358'), u'lng': Decimal('72.90858159999999')}
ChIJ88dcaObH5zsRWLT4KyCLkI8
The Yellow Chilli

现在我想了解每家餐厅的详细信息(例如他们的评分、评论、时间)。 place_id如何获取信息?

【问题讨论】:

  • 尝试拨打place.get_details(),然后拨打place.details。它是一个字典对象。
  • @Kris 但place.details 只返回有关 1 家餐厅的信息。我的query_result中有 20 个

标签: python google-places-api


【解决方案1】:

请参阅此(向下滚动查看文档):

https://github.com/slimkrazy/python-google-places

它有你需要的所有电话。例如:

for place in query_result.places:
    place.get_details()
    print place.rating

将获得您的每个地点的评分。几乎所有内容都在你的 github 链接中:)

【讨论】:

  • 我只关注这个链接.. 但是当我在上面的命令for place in query_result.places: print place.rating 上触发时,它会返回4-5 家餐厅的信息,然后引发错误GooglePlacesAttributeError: The attribute requested is only available after an explicit call to get_details() is made.
  • @user2927983 首先致电place.get_details()。我将编辑我的答案。
  • @Kris 我正在尝试使用这种方法GooglePlaces.get_place(place_id ="ChIJSWijB-bH5zsRVLE5ipsxvHU"),但它返回错误。 TypeError: unbound method get_place() must be called with GooglePlaces instance as first argument (got nothing instead)这个不知道怎么处理
  • 我是 python 新手.. 不知道该怎么做.. 抱歉这个愚蠢的问题。你能帮忙吗?
  • 我不是个聪明人。试试这个:google_places.get_place(place_id ="ChIJSWijB-bH5zsRVLE5ipsxvHU")。您的调用是正确的,但您需要从类的实例调用方法 GooglePlaces
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-12-23
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
  • 2012-03-20
  • 1970-01-01
相关资源
最近更新 更多