在附近的 lat_lng Google 个地方搜索 api (python)
Searching nearby lat_lng in Google places api (python)
我正在尝试查找 lat_lng 中特定位置附近的所有地点。但是,在搜索 lat_lng 而不是位置 (location='location') 时出现错误。我有 Google 地点 API Web 服务和 Google 地图地理编码 API 的密钥。根据 https://github.com/slimkrazy/python-google-places 这应该足够了。
这是我的代码和错误消息:
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)
错误信息:
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
有人知道如何解决这个问题吗?
根据您提供的 github,参考部分指出 lat_lng 参数的类型为 dict:
lat_lng -- A dict containing the following keys: lat, lng (default None)
改为执行以下操作:
query_result = google_places.nearby_search(
lat_lng={'lat': 52.0737017, 'lng': 5.0944107999999915},
radius=100,
types=[types.TYPE_RESTAURANT] or [types.TYPE_CAFE])
要查看 query_result,只需执行以下操作:
query_result.raw_response
我正在尝试查找 lat_lng 中特定位置附近的所有地点。但是,在搜索 lat_lng 而不是位置 (location='location') 时出现错误。我有 Google 地点 API Web 服务和 Google 地图地理编码 API 的密钥。根据 https://github.com/slimkrazy/python-google-places 这应该足够了。
这是我的代码和错误消息:
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)
错误信息:
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
有人知道如何解决这个问题吗?
根据您提供的 github,参考部分指出 lat_lng 参数的类型为 dict:
lat_lng -- A dict containing the following keys: lat, lng (default None)
改为执行以下操作:
query_result = google_places.nearby_search(
lat_lng={'lat': 52.0737017, 'lng': 5.0944107999999915},
radius=100,
types=[types.TYPE_RESTAURANT] or [types.TYPE_CAFE])
要查看 query_result,只需执行以下操作:
query_result.raw_response