我已按照http://code.google.com/p/geopy/wiki/GettingStarted中的教程进行操作 这很好用:
g = geocoders.Google(resource='maps')
我想使用json作为输出格式,因为我想在javascript中处理结果。
但每次我都使用:
g = geocoders.Google(resource='maps', output_format='json')
我收到以下错误:
Environment:
Request Method: GET
Request URL: http://localhost:8000/business/view/13/
Django Version: 1.2.1
Python Version: 2.5.1
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'registration',
'pley.business',
'pley.review',
'django.contrib.admin',
'django.contrib.webdesign']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "C:\Python25\Lib\site-packages\django\core\handlers\base.py" in get_response
100. response = callback(request, *callback_args, **callback_kwargs)
File "C:\django\pley\..\pley\business\views.py" in business_view
57. for place, (lat, lng) in g.geocode(string_location,exactly_one=False):
File "c:\python25\lib\site-packages\geopy-0.94-py2.5.egg\geopy\geocoders\google.py" in geocode
66. return self.geocode_url(url, exactly_one)
File "c:\python25\lib\site-packages\geopy-0.94-py2.5.egg\geopy\geocoders\google.py" in geocode_url
73. return dispatch(page, exactly_one)
File "c:\python25\lib\site-packages\geopy-0.94-py2.5.egg\geopy\geocoders\google.py" in parse_json
123. json = simplejson.loads(page)
File "C:\Python25\lib\site-packages\simplejson-2.1.1-py2.5-win32.egg\simplejson\__init__.py" in loads
384. return _default_decoder.decode(s)
File "C:\Python25\lib\site-packages\simplejson-2.1.1-py2.5-win32.egg\simplejson\decoder.py" in decode
402. obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python25\lib\site-packages\simplejson-2.1.1-py2.5-win32.egg\simplejson\decoder.py" in raw_decode
420. raise JSONDecodeError("No JSON object could be decoded", s, idx)
Exception Type: JSONDecodeError at /business/view/13/
Exception Value: No JSON object could be decoded: line 1 column 0 (char 0)
非常感谢任何建议/回复。
谢谢!
答案 0 :(得分:0)
您是否阅读过geopy页面上的评论?
gregor.horvath的评论,9月11日, 2009年
请注意,尽管有 不同的output_format参数 地理编码器,实际输出 地理编码功能的格式是 总是一样的:
位置,(latttude,经度)
output_format仅指 地理编码器服务的输出 (谷歌等),而不是输出 地理编码功能。