我已经做了好几次,通过解析包含Chinese.But地址信息的Google来获得地址,当我在手机中显示地址时,它都是英文的。
我从下面的网址上得到了json。http://maps.googleapis.com/maps/api/geocode/json?address=wuhan&sensor=false
编辑:与我分享的答案与工作解决方案:
StringBuffer sb=new StringBuffer();
sb.append("http://maps.googleapis.com/maps/api/geocode/json?latlng=").append(latStr).append(',').append(lonStr).append("&sensor=false&Accept-Language:zh-CN");
String url=sb.toString();
HttpClient httpClient=new DefaultHttpClient();
String responseData="";
try {
HttpResponse response=httpClient.execute(new HttpGet(url));
response.addHeader("Accept-Language", "zh-CN");
HttpEntity entity=response.getEntity();
BufferedReader bf=new BufferedReader(new InputStreamReader((entity.getContent()),"UTF-8"));
String line="";
while((line=bf.readLine())!=null){
responseData=responseData+line;
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}发布于 2012-01-11 15:52:51
只需将Accept-Language添加到reaquest,因为默认情况下,google将返回英语fx.:Accept-Language: zh-CN格式的信息。
编辑(因为OP在四处游荡):
如果您使用的是java.net.HttpURLConnection connection;,那么请使用:
connection.setRequestProperty ( "Accept-Language", "zh-CN");
如果是org.apache.http.client.methods.HttpGet request;,那么:
request.addHeader("Accept-Language", "zh-CN");
我刚在fiddler2上测试过
和用于
GET /maps/api/geocode/json?address=wuhan&sensor=false HTTP/1.0
Host: maps.googleapis.com
Accept-Language: zh-CN我得到了
{
"results" : [
{
"address_components" : [
{
"long_name" : "武汉",
"short_name" : "武汉",
"types" : [ "locality", "political" ]
},
{
"long_name" : "湖北省",
"short_name" : "湖北省",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "中国",
"short_name" : "CN",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "中国湖北省武汉市",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 31.36126030,
"lng" : 115.08257280
},
"southwest" : {
"lat" : 29.96907670,
"lng" : 113.70228110
}
},
"location" : {
"lat" : 30.5930870,
"lng" : 114.3053570
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 30.78745989999999,
"lng" : 114.6189880
},
"southwest" : {
"lat" : 30.34877210,
"lng" : 113.9817810
}
}
},
"types" : [ "locality", "political" ]
}
],
"status" : "OK"
}https://stackoverflow.com/questions/8822089
复制相似问题