使用 google 个地方 api 时出现 lat_lng 错误
getting lat_lng error while using google places api
我正在使用 Google Places API 和 Python 构建一个聊天机器人应用程序来推荐附近的地方。
我指的是下面的link:
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
它在 link 本身中给出。但是,我不断收到以下错误:
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 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
它的意思是它试图寻找 google 以获得 "Mumbai" 的 lat_lng 对,但请求失败,因为它被拒绝了。使用来自 Google 的有效 API 密钥,它应该可以工作。
我正在使用 Google Places API 和 Python 构建一个聊天机器人应用程序来推荐附近的地方。
我指的是下面的link: 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
它在 link 本身中给出。但是,我不断收到以下错误:
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 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
它的意思是它试图寻找 google 以获得 "Mumbai" 的 lat_lng 对,但请求失败,因为它被拒绝了。使用来自 Google 的有效 API 密钥,它应该可以工作。