[英]Searching nearby lat_lng in Google places api (python)
我試圖在 lat_lng 中找到某個位置附近的所有地方。 但是,在搜索 lat_lng 而不是位置 (location='location') 時出現錯誤。 我有一個用於 Google Places API Web Service 和 Google Maps Geocoding 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 -- 包含以下鍵的字典:lat、lng(默認為無)
請改為執行以下操作:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.