注意ak的值得获取,
HttpPost request;
try {
//request = new HttpPost(new URI("http://api.map.baidu.com/location/ip?ak=MRS3m80V3z2FRG5fB1RZQKlI&coor=bd09ll"));
request = new HttpPost(new URI("http://api.map.baidu.com/location/ip?ak=MRS3m80V3z2FRG5fB1RZQKlI&ip=202.198.16.3&coor=bd09ll"));
// 先封装一个 JSON 对象
// 发送请求
HttpResponse httpResponse = new DefaultHttpClient().execute(request);
// 得到应答的字符串,这也是一个 JSON 格式保存的数据
String retSrc = EntityUtils.toString(httpResponse.getEntity());
// 生成 JSON 对象
JSONObject result = new JSONObject(retSrc);
JSONObject content=result.getJSONObject("content");
System.out.println("result:"+content.getString("address"));
//Toast.makeText(MainActivity.this, "result:"+result.getString("address"), 200).show();
//String token = result.get("token");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
结果: