//利用google api 翻译
private void _Translate(String strEnglish) {
String strURL = String
.format(
"http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=%s&langpair=en%%7Czh-CN",
URLEncoder.encode(strEnglish));
Log.d(LOG_TAG, strURL);
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(strURL);
HttpResponse response = httpclient.execute(httpget);
HttpEntity entityOut = response.getEntity();
if (entityOut != null) {
BufferedReader br = new BufferedReader(new InputStreamReader(
entityOut.getContent()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
Log.d(LOG_TAG, sb.toString());
JSONObject json = new JSONObject(sb.toString());
JSONObject jsonResponse = json.getJSONObject("responseData");
if (jsonResponse != null) {
String strChinese = jsonResponse
.getString("translatedText");
m_edChinese.setText(strChinese);
} else {
m_edChinese.setText(sb.toString());
}
}
} catch (Exception e) {
Log.d(LOG_TAG, e.toString());
}
}
//利用google api 根据国家的代称获取国家的部分城市名称及经纬度
// HttpgetClient使用get方法得到数据并返回
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(
"http://www.google.com/ig/cities?country=" + newstr+"&hl=zh_cn");
HttpResponse response = httpclient.execute(httpget);
HttpEntity entityOut = response.getEntity();
if (entityOut != null) {
BufferedReader rd = new BufferedReader(
new InputStreamReader(entityOut.getContent()
,"GBK"));
StringBuffer sb = new StringBuffer();
String line;
while ((line = rd.readLine()) != null) {
sb.append(line);
}
// 将得到的JSON放到map里
JSONObject jobj = new JSONObject(sb.toString());
JSONArray jArray = jobj.getJSONArray("cities");
for (int i = 0; i < jArray.length(); i++) {
Map<String, Object> map = new HashMap<String, Object>();
JSONObject jo = jArray.getJSONObject(i);
String provice = jo.getString("name");
Log.v("xiao", provice);
map.put("name", "城市名:" + provice);
String lat = jo.getString("lat");
map.put("lat", "精度:" + lat);
String lon = jo.getString("lon");
map.put("lon", "维度:" + lon);
list.add((HashMap<String, Object>) map);
}