日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

20220626-JAVA高德地图天气API调用总结

發(fā)布時間:2023/12/10 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 20220626-JAVA高德地图天气API调用总结 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

AutoNavi——Weather API Usage

Background

I need information of weather forecast ,so I choose AutoNavi API as it is widely used in China


Website
https://lbs.amap.com
Apply for Key

Document Download
https://lbs.amap.com/api/webservice/download#部分數據<adcode> 廈門市 350200 0592 廈門市市轄區(qū) 350201 0592 思明區(qū) 350203 0592 海滄區(qū) 350205 0592 湖里區(qū) 350206 0592 集美區(qū) 350211 0592 同安區(qū) 350212 0592 翔安區(qū) 350213 0592
API format
#返回預報天氣 https://restapi.amap.com/v3/weather/weatherInfo?city=<adcode>&key=<用戶key>&extensions=all #返回實況天氣 https://restapi.amap.com/v3/weather/weatherInfo?city=<adcode>&key=<用戶key>&extensions=base
Json Entities Class
@Data public class WeatherDTO {private String status;private String count;private String info;private String infocode;private ArrayList<Forecast> forecasts; }@Data public class Forecast {private String city;private String adcode;private String province;private String reporttime;private ArrayList<Cast> 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 = "***************"; /*** 區(qū)號** @param adCode* @return* @throws IOException*/ public static WeatherDTO getWeatherObj(String adCode) throws IOException {// OkHtppUtil ou1 = new OkHtppUtil();//目前的日期 // 湖里區(qū) 350206 0592 // 集美區(qū) 350211 0592 // 同安區(qū) 350212 0592String response3 = OU.getMethod("https://restapi.amap.com/v3/weather/weatherInfo?city=" + adCode + "&key=" + AMAP_KEY + "&extensions=all");return JSON.parseObject(response3, WeatherDTO.class);}/*** 將json對象轉為可讀的html文本,+br處理** @param adCode* @return* @throws IOException*/public static String getWeather(String adCode) {try {WeatherDTO weatherDTO = getWeatherObj(adCode);ArrayList<Forecast> forecasts = weatherDTO.getForecasts();Forecast one = forecasts.get(0);ArrayList<Cast> casts = one.getCasts();String content = "";if (casts == null) {content = "上方云層異常,瘋狂布朗運動ing,暫無天氣預報更新!————404";return content;}content = "地區(qū):<b>" + one.getCity() + "</b>,更新時間:" + one.getReporttime() + "<br>";for (Cast cast : casts) {content += cast.getDate() + "————天氣:" + cast.getDayweather() + ";氣溫:" + cast.getNighttemp() + "~" + cast.getDaytemp() + "℃;風力:" + cast.getDaypower() + "級" + cast.getDaywind() + "風<br>";}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.

總結

以上是生活随笔為你收集整理的20220626-JAVA高德地图天气API调用总结的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。