繁体   English   中英

使用Google Places API时出现lat_lng错误

[英]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.

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