self.api_key = api_key
self.api = "http://www.mapquestapi.com/geocoding/v1/address?"
def geocode(self, query, exactly_one=True, timeout=None): # pylint: disable=W0221
"""
Geocode a location query.
:param string query: The address or query you wish to geocode.
:param bool exactly_one: Return one result or a list of results, if
available.
:param int timeout: Time, in seconds, to wait for the geocoding service
to respond before raising a :class:`geopy.exc.GeocoderTimedOut`
exception. Set this only if you wish to override, on this call
only, the value set during the geocoder's initialization.
.. versionadded:: 0.97
"""
params = {
'key': self.api_key,
'location': self.format_string % query
}
if exactly_one:
params['maxResults'] = 1
url = "&".join((self.api, urlencode(params)))
print url # Print the URL just to make sure it's produced correctly
我也试过同样的方法,结果也一样。在检查了库之后,我发现错误引用了请求所在的行,而且看起来,API密钥没有被传输。如果在init语句中没有添加键,那么api_key='',所以我试图将我自己的文件库中的第66行改为我的键。在
还是没有成功!密钥本身有效,我通过调用库中调用的URL进行了测试: http://open.mapquestapi.com/nominatim/v1/search.php?key=“我的密钥”&format=json&json\u callback=renderbasicsearch叙事&q=westminster+abbey
不知道为什么这样不行
在干杯.kg在
我修好这个有点进步。我能够正确地编写查询,但是json解析有点让我为难。也许有人知道。我知道url被正确地发送了(我在浏览器中检查了它,它返回了一个json对象)。也许有人知道如何解析返回的json对象,使其最终工作。在
无论如何,我必须进入
openmapquest.py
源代码,从第66行开始,我做了以下修改:现在任务仍然是让
_parse_json
函数工作。在相关问题 更多 >
编程相关推荐