def baidu_geo_api(sight_name):
sight_name = sight_name.decode('utf-8')
ak = 'qsQB3G3zIR1SvZ01bEIAMBHGbCCUhTgm'
url = 'http://api.map.baidu.com/geocoder/v2/?output=json&address=%s&ak=%s' % (sight_name, ak)
log.msg('run into baidu_geo_api at line 123, url: ' + url, log.INFO)
try:
response = urllib2.urlopen(url.encode('utf-8'))
result = response.read()
json_text = json.loads(result)
if json_text.get('status') != 1:
lng = json_text.get('result').get('location').get('lng')
lng = float('%.2f' % lng)
lat = json_text.get('result').get('location').get('lat')
lat = float('%.2f' % lat)
print 'lng: %d, lat: %d' % (lng, lat)
return lng, lat
else:
log.msg('response status is 1 at line 132,' + sight_name, level=log.INFO)
return 1, 1
except urllib2.HTTPError as e:
print 'HttpError in baidu_geo_api at line 40 %s' % e
except TypeError as e:
print 'TypeError in baidu_geo_api at line 53 %s' % e
评论列表
文章目录