[英]getting lat_lng error while using google places api
我正在將Google Places API與Python結合使用,以構建一個聊天機器人應用程序來建議附近的地方。
我指的是以下鏈接: https : //github.com/slimkrazy/python-google-places
我正在做這樣的事情:
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
它在鏈接本身中給出。 但是,我不斷收到以下錯誤:
Traceback (most recent call last):
File "run.py", line 9, in <module>
radius=1000, types=[types.TYPE_RESTAURANT])
File "/home/neetu/Desktop/python-google-places/googleplaces/__init__.py", line 281, in nearby_search
lat_lng_str = self._generate_lat_lng_string(lat_lng, location)
File "/home/neetu/Desktop/python-google-places/googleplaces/__init__.py", line 593, in _generate_lat_lng_string
'lat_lng must be a dict with the keys, \'lat\' and \'lng\'. Cause: %s' % str(e))
ValueError: lat_lng must be a dict with the keys, 'lat' and 'lng'. Cause: Request to URL https://maps.googleapis.com/maps/api/geocode/json?sensor=false&key=AIzaSyAiFpFd85eMtfbvmVNEYuNds5TEF9FjIPI&address=Mumbai failed with response code: REQUEST_DENIED
任何幫助都非常歡迎:)
根據文檔: https : //github.com/slimkrazy/python-google-places/blob/master/googleplaces/ init .py :
您應該能夠提供一個位置而不是lat_lng對,但是您可以嘗試提供lat_lng而不是位置。
嘗試刪除:
location="Mumbai"
並添加
lat_lng={'lat:19.148320, 'lng':72.888794}
仔細閱讀代碼后,我了解了該錯誤。 您得到的錯誤是:
ValueError:lat_lng必須是帶有鍵“ lat”和“ lng”的字典。 原因:>請求URL https://maps.googleapis.com/maps/api/geocode/json嗎?> sensor = false&key = AIzaSyAiFpFd85eMtfbvmVNEYuNds5TEF9FjIPI&address =孟買失敗>具有響應代碼:REQUEST_DENIED
它的意思是,它試圖通過google獲取“孟買”的lat_lng對,但該請求失敗了,因為它被拒絕了。 使用來自Google的有效API密鑰,即可使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.