简体   繁体   English

在 Google 地方 api (python) 中搜索附近的 lat_lng

[英]Searching nearby lat_lng in Google places api (python)

I am trying to find all places nearby a certain location in lat_lng.我试图在 lat_lng 中找到某个位置附近的所有地方。 However I get an error when searching for a lat_lng instead of a location (location='location').但是,在搜索 lat_lng 而不是位置 (location='location') 时出现错误。 I've got a key for the Google places API Web Service and Google Maps Geocoding API.我有一个用于 Google Places API Web Service 和 Google Maps Geocoding API 的密钥。 Accoring to https://github.com/slimkrazy/python-google-places this should be enough.根据https://github.com/slimkrazy/python-google-places这应该足够了。

This is my code and my error message:这是我的代码和我的错误信息:

YOUR_API_KEY = 'API_KEY'
google_places = GooglePlaces(YOUR_API_KEY)

query_result = google_places.nearby_search(
        lat_lng='52.0737017, 5.0944107999999915', 
        radius=100,
        types=[types.TYPE_RESTAURANT] or [types.TYPE_CAFE])

for place in query_result.places:
     place.get_details()
     print '%s %s %s' % (place.name, place.geo_location, place.types)

Error message:错误信息:

File "C:\Python27\lib\site-packages\googleplaces\__init__.py", line 281, in nearby_search
    lat_lng_str = self._generate_lat_lng_string(lat_lng, location)
  File "C:\Python27\lib\site-packages\googleplaces\__init__.py", line 590, in _generate_lat_lng_string
    else geocode_location(location=location, api_key=self.api_key))
TypeError: format requires a mapping

Anyone who knows how to fix this problem?有谁知道如何解决这个问题?

From the github you provided, the reference section states the lat_lng parameter is of type dict :从您提供的github 中,参考部分指出 lat_lng 参数的类型为dict

lat_lng -- A dict containing the following keys: lat, lng (default None) lat_lng -- 包含以下键的字典:lat、lng(默认为无)

Do the following instead:请改为执行以下操作:

query_result = google_places.nearby_search(
        lat_lng={'lat': 52.0737017, 'lng': 5.0944107999999915}, 
        radius=100,
        types=[types.TYPE_RESTAURANT] or [types.TYPE_CAFE])

To see the query_result, simply do:要查看 query_result,只需执行以下操作:

query_result.raw_response

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM