获取天气

1  //根据经纬度获取城市名
public static String getCityNameByLan(String lng,String lat){
try{
String url="http://api.map.baidu.com/geocoder?location="+lat+","+lng+"&output=json";
MyHttpClientResponseResult r= MyHttpClientUtil.requestGet(url);
String s = r.getResponseContent();
JSONObject k = JSONObject.parseObject(s);
String t = k.getJSONObject("result").getJSONObject("addressComponent").getString("city");
return t;
}catch (Exception e){
return "1";
}
}


2 根据城市获取天气数据
MyHttpClientResponseResult r= MyHttpClientUtil.requestGet("http://wthrcdn.etouch.cn/weather_mini?city="+city);


posted @ 2022-04-21 13:54  冬天不眠  阅读(50)  评论(0编辑  收藏  举报