I need information of weather forecast ,so I choose AutoNavi API as it is widely used in China
Website
https://lbs.amap.comApply for Key Document Download
https://lbs.amap.com/api/webservice/download #部分数据 厦门市 350200 0592 厦门市市辖区 350201 0592 思明区 350203 0592 海沧区 350205 0592 湖里区 350206 0592 集美区 350211 0592 同安区 350212 0592 翔安区 350213 0592API format
#返回预报天气 https://restapi.amap.com/v3/weather/weatherInfo?city=>&key=<用户key>&extensions=all #返回实况天气 https://restapi.amap.com/v3/weather/weatherInfo?city=>&key=<用户key>&extensions=baseJson Entities Class
@Data
public class WeatherDTO {
private String status;
private String count;
private String info;
private String infocode;
private ArrayList forecasts;
}
@Data
public class Forecast {
private String city;
private String adcode;
private String province;
private String reporttime;
private ArrayList casts;
}
@Data
public class Cast {
private String date;
private String week;
private String dayweather;
private String nightweather;
private String daytemp;
private String nighttemp;
private String daywind;
private String nightwind;
private String daypower;
private String nightpower;
}
Code Reference
private static final OkHtppUtil OU = new OkHtppUtil();
private static final String AMAP_KEY = "***************";
public static WeatherDTO getWeatherObj(String adCode) throws IOException {
// OkHtppUtil ou1 = new OkHtppUtil();
//目前的日期
// 湖里区 350206 0592
// 集美区 350211 0592
// 同安区 350212 0592
String response3 = OU.getMethod("https://restapi.amap.com/v3/weather/weatherInfo?city=" + adCode + "&key=" + AMAP_KEY + "&extensions=all");
return JSON.parseObject(response3, WeatherDTO.class);
}
public static String getWeather(String adCode) {
try {
WeatherDTO weatherDTO = getWeatherObj(adCode);
ArrayList forecasts = weatherDTO.getForecasts();
Forecast one = forecasts.get(0);
ArrayList casts = one.getCasts();
String content = "";
if (casts == null) {
content = "上方云层异常,疯狂布朗运动ing,暂无天气预报更新!————404";
return content;
}
content = "地区:" + one.getCity() + ",更新时间:" + one.getReporttime() + "
";
for (Cast cast : casts) {
content += cast.getDate() + "————天气:" + cast.getDayweather() + ";气温:" + cast.getNighttemp() + "~" + cast.getDaytemp() + "℃;风力:" + cast.getDaypower() + "级" + cast.getDaywind() + "风
";
}
return content;
} catch (IOException e) {
return "上方云层异常,疯狂布朗运动ing,暂无天气预报更新!————403";
}
}
Finally
It is no exaggeration to say that it’s easy to use. There are many other APIs in AutoNavi, hope I could use some of them in the future if possible.



