码迷,mamicode.com
首页 > 编程语言 > 详细

java获取天气预报数据

时间:2014-08-05 23:03:31      阅读:474      评论:0      收藏:0      [点我收藏+]

标签:城市地区代号编码   天气预报   java获取天气预报接口   java获取天气预报数据   

获取天气预报数据

对于做web项目有天气数据的需求,这个服务很合适:

WebXml.com.cn 2400多个城市天气预报Web服务,包含2300个以上中国城市和100个以上国外城市天气预报数据。数据每2.5小时左右自动更新一次,准确可靠。提供webservice 接口,主连接:http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/

方法调用说明如下:

1getRegionCountry 获得国外国家名称和与之对应的ID

说明:输入参数:无,

返回数据:一维字符串数组如下:

<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://WebXml.com.cn/">

<string>阿尔及利亚,3320</string>

<string>阿根廷,3522</string>

<string>阿曼,3170</string>

<string>阿塞拜疆,3176</string>

<string>埃及,3317</string>

<string>埃塞俄比亚,3314</string>

<string>爱尔兰,3246</string>

<string>奥地利,3237</string>

<string>澳大利亚,368</string>

<string>巴基斯坦,3169</string>

<string>巴西,3580</string>

<string>保加利亚,3232</string>

<string>比利时,3243</string>

<string>波兰,3235</string>

<string>朝鲜,3163</string>

<string>丹麦,3245</string>

<string>德国,3238</string>

<string>俄罗斯,3225</string>

<string>法国,3241</string>

<string>菲律宾,3151</string>

<string>芬兰,3248</string>

<string>刚果(金),3377</string>

<string>哥伦比亚,3524</string>

<string>古巴,344</string>

<string>韩国,3162</string>

<string>荷兰,3244</string>

<string>加拿大,347</string>

<string>加纳,3313</string>

<string>柬埔寨,3154</string>

<string>捷克,3236</string>

<string>克罗地亚,3233</string>

<string>肯尼亚,3316</string>

<string>拉托维亚,3228</string>

<string>老挝,3155</string>

<string>立陶宛,3227</string>

<string>马达加斯加,3312</string>

<string>马尔代夫,3166</string>

<string>马来西亚,3158</string>

<string>马里,3319</string>

<string>美国,346</string>

<string>蒙古,3165</string>

<string>秘鲁,3578</string>

<string>缅甸,3160</string>

<string>莫桑比克,3311</string>

<string>墨西哥,345</string>

<string>南非,3310</string>

<string>尼泊尔,3164</string>

<string>尼日利亚,3379</string>

<string>挪威,3250</string>

<string>葡萄牙,3239</string>

<string>日本,3161</string>

<string>瑞典,3249</string>

<string>瑞士,3242</string>

<string>塞内加尔,3318</string>

<string>沙特阿拉伯,3172</string>

<string>斯里兰卡,3167</string>

<string>泰国,3159</string>

<string>坦桑尼亚,3315</string>

<string>突尼斯,3321</string>

<string>土耳其,3229</string>

<string>委内瑞拉,342</string>

<string>文莱,3153</string>

<string>乌克兰,3226</string>

<string>乌兹别克斯坦,3175</string>

<string>西班牙,3240</string>

<string>希腊,3230</string>

<string>新加坡,3157</string>

<string>新西兰,369</string>

<string>匈牙利,3234</string>

<string>叙利亚,3174</string>

<string>牙买加,343</string>

<string>伊朗,3171</string>

<string>意大利,3231</string>

<string>印度,3168</string>

<string>印度尼西亚,3152</string>

<string>英国,3247</string>

<string>约旦,3173</string>

<string>越南,3156</string>

<string>智利,3523</string>

</ArrayOfString>

 

2getRegionDataset 获得中国省份、直辖市、地区;国家名称(国外)和与之对应的ID

说明:输入参数:无,

返回数据:DataSet—如下:

<Province diffgr:id="Province1" msdata:rowOrder="0">

<RegionID>3113</RegionID>

<RegionName>黑龙江</RegionName>

</Province>

<Province diffgr:id="Province2" msdata:rowOrder="1">

<RegionID>3114</RegionID>

<RegionName>吉林</RegionName>

</Province>

<Province diffgr:id="Province3" msdata:rowOrder="2">

<RegionID>3115</RegionID>

<RegionName>辽宁</RegionName>

</Province>

<Province diffgr:id="Province4" msdata:rowOrder="3">

<RegionID>3116</RegionID>

<RegionName>内蒙古</RegionName>

</Province>

<Province diffgr:id="Province5" msdata:rowOrder="4">

<RegionID>3117</RegionID>

<RegionName>河北</RegionName>

</Province>

<Province diffgr:id="Province6" msdata:rowOrder="5">

<RegionID>3118</RegionID>

<RegionName>河南</RegionName>

</Province>

<Province diffgr:id="Province7" msdata:rowOrder="6">

<RegionID>3119</RegionID>

<RegionName>山东</RegionName>

</Province>

<Province diffgr:id="Province8" msdata:rowOrder="7">

<RegionID>31110</RegionID>

<RegionName>山西</RegionName>

</Province>

<Province diffgr:id="Province9" msdata:rowOrder="8">

<RegionID>31111</RegionID>

<RegionName>江苏</RegionName>

</Province>

<Province diffgr:id="Province10" msdata:rowOrder="9">

<RegionID>31112</RegionID>

<RegionName>安徽</RegionName>

</Province>

<Province diffgr:id="Province11" msdata:rowOrder="10">

<RegionID>31113</RegionID>

<RegionName>陕西</RegionName>

</Province>

<Province diffgr:id="Province12" msdata:rowOrder="11">

<RegionID>31114</RegionID>

<RegionName>宁夏</RegionName>

</Province>

<Province diffgr:id="Province13" msdata:rowOrder="12">

<RegionID>31115</RegionID>

<RegionName>甘肃</RegionName>

</Province>

<Province diffgr:id="Province14" msdata:rowOrder="13">

<RegionID>31116</RegionID>

<RegionName>青海</RegionName>

</Province>

<Province diffgr:id="Province15" msdata:rowOrder="14">

<RegionID>31117</RegionID>

<RegionName>湖北</RegionName>

</Province>

<Province diffgr:id="Province16" msdata:rowOrder="15">

<RegionID>31118</RegionID>

<RegionName>湖南</RegionName>

</Province>

<Province diffgr:id="Province17" msdata:rowOrder="16">

<RegionID>31119</RegionID>

<RegionName>浙江</RegionName>

</Province>

<Province diffgr:id="Province18" msdata:rowOrder="17">

<RegionID>31120</RegionID>

<RegionName>江西</RegionName>

</Province>

<Province diffgr:id="Province19" msdata:rowOrder="18">

<RegionID>31121</RegionID>

<RegionName>福建</RegionName>

</Province>

<Province diffgr:id="Province20" msdata:rowOrder="19">

<RegionID>31122</RegionID>

<RegionName>贵州</RegionName>

</Province>

<Province diffgr:id="Province21" msdata:rowOrder="20">

<RegionID>31123</RegionID>

<RegionName>四川</RegionName>

</Province>

<Province diffgr:id="Province22" msdata:rowOrder="21">

<RegionID>31124</RegionID>

<RegionName>广东</RegionName>

</Province>

<Province diffgr:id="Province23" msdata:rowOrder="22">

<RegionID>31125</RegionID>

<RegionName>广西</RegionName>

</Province>

<Province diffgr:id="Province24" msdata:rowOrder="23">

<RegionID>31126</RegionID>

<RegionName>云南</RegionName>

</Province>

<Province diffgr:id="Province25" msdata:rowOrder="24">

<RegionID>31127</RegionID>

<RegionName>海南</RegionName>

</Province>

<Province diffgr:id="Province26" msdata:rowOrder="25">

<RegionID>31128</RegionID>

<RegionName>新疆</RegionName>

</Province>

<Province diffgr:id="Province27" msdata:rowOrder="26">

<RegionID>31129</RegionID>

<RegionName>西藏</RegionName>

</Province>

<Province diffgr:id="Province28" msdata:rowOrder="27">

<RegionID>31130</RegionID>

<RegionName>台湾</RegionName>

</Province>

<Province diffgr:id="Province29" msdata:rowOrder="28" diffgr:hasChanges="inserted">

<RegionID>311101</RegionID>

<RegionName>北京</RegionName>

</Province>

<Province diffgr:id="Province30" msdata:rowOrder="29" diffgr:hasChanges="inserted">

<RegionID>311102</RegionID>

<RegionName>上海</RegionName>

</Province>

<Province diffgr:id="Province31" msdata:rowOrder="30" diffgr:hasChanges="inserted">

<RegionID>311103</RegionID>

<RegionName>天津</RegionName>

</Province>

<Province diffgr:id="Province32" msdata:rowOrder="31" diffgr:hasChanges="inserted">

<RegionID>311104</RegionID>

<RegionName>重庆</RegionName>

</Province>

<Province diffgr:id="Province33" msdata:rowOrder="32" diffgr:hasChanges="inserted">

<RegionID>311201</RegionID>

<RegionName>香港</RegionName>

</Province>

<Province diffgr:id="Province34" msdata:rowOrder="33" diffgr:hasChanges="inserted">

<RegionID>311202</RegionID>

<RegionName>澳门</RegionName>

</Province>

<Province diffgr:id="Province35" msdata:rowOrder="34" diffgr:hasChanges="inserted">

<RegionID>311203</RegionID>

<RegionName>钓鱼岛</RegionName>

</Province>

<Country diffgr:id="Country1" msdata:rowOrder="0">

<RegionID>3320</RegionID>

<RegionName>阿尔及利亚</RegionName>

</Country>

<Country diffgr:id="Country2" msdata:rowOrder="1">

<RegionID>3522</RegionID>

<RegionName>阿根廷</RegionName>

</Country>

<Country diffgr:id="Country3" msdata:rowOrder="2">

<RegionID>3170</RegionID>

<RegionName>阿曼</RegionName>

</Country>

<Country diffgr:id="Country4" msdata:rowOrder="3">

<RegionID>3176</RegionID>

<RegionName>阿塞拜疆</RegionName>

</Country>

<Country diffgr:id="Country5" msdata:rowOrder="4">

<RegionID>3317</RegionID>

<RegionName>埃及</RegionName>

</Country>

<Country diffgr:id="Country6" msdata:rowOrder="5">

<RegionID>3314</RegionID>

<RegionName>埃塞俄比亚</RegionName>

</Country>

<Country diffgr:id="Country7" msdata:rowOrder="6">

<RegionID>3246</RegionID>

<RegionName>爱尔兰</RegionName>

</Country>

<Country diffgr:id="Country8" msdata:rowOrder="7">

<RegionID>3237</RegionID>

<RegionName>奥地利</RegionName>

</Country>

<Country diffgr:id="Country9" msdata:rowOrder="8">

<RegionID>368</RegionID>

<RegionName>澳大利亚</RegionName>

</Country>

<Country diffgr:id="Country10" msdata:rowOrder="9">

<RegionID>3169</RegionID>

<RegionName>巴基斯坦</RegionName>

</Country>

<Country diffgr:id="Country11" msdata:rowOrder="10">

<RegionID>3580</RegionID>

<RegionName>巴西</RegionName>

</Country>

<Country diffgr:id="Country12" msdata:rowOrder="11">

<RegionID>3232</RegionID>

<RegionName>保加利亚</RegionName>

</Country>

<Country diffgr:id="Country13" msdata:rowOrder="12">

<RegionID>3243</RegionID>

<RegionName>比利时</RegionName>

</Country>

<Country diffgr:id="Country14" msdata:rowOrder="13">

<RegionID>3235</RegionID>

<RegionName>波兰</RegionName>

</Country>

<Country diffgr:id="Country15" msdata:rowOrder="14">

<RegionID>3163</RegionID>

<RegionName>朝鲜</RegionName>

</Country>

 

3获得支持的城市/地区名称和与之对应的ID

getSupportCityDataset 

说明:输入参数:theRegionCode = 省市、国家ID或名称,

返回数据:DataSet

   getSupportCityString 

说明:输入参数:theRegionCode = 省市、国家ID或名称,

返回数据:一维字符串数组。

 

例如:我想找到河北(3117)各个地区的ID:

链接:http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/getSupportCityString?theRegionCode=3117

返回数据如下:

<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://WebXml.com.cn/">

<string>安国,832</string>

<string>安平,837</string>

<string>安新,833</string>

<string>北戴河,3445</string>

<string>霸州,798</string>

<string>柏乡,12</string>

<string>保定,830</string>

<string>泊头,846</string>

<string>沧州,844</string>

<string>昌黎,816</string>

<string>大名,919</string>

<string>成安,611</string>

<string>承德,755</string>

<string>任县,525</string>

<string>承德县,760</string>

<string>赤城,744</string>

<string>崇礼,699</string>

<string>磁县,538</string>

<string>大厂,791</string>

<string>大城,841</string>

<string>定州,451</string>

<string>东光,878</string>

<string>肥乡,595</string>

<string>丰南,812</string>

<string>丰宁,701</string>

<string>丰润,811</string>

<string>馆陶,924</string>

<string>峰峰,535</string>

<string>抚宁,817</string>

<string>阜城,875</string>

<string>阜平,445</string>

<string>高碑店,789</string>

<string>高阳,831</string>

<string>高邑,17</string>

<string>藁城,452</string>

<string>沽源,698</string>

<string>固安,793</string>

<string>故城,872</string>

<string>广平,540</string>

<string>广宗,856</string>

<string>海兴,855</string>

<string>邯郸,533</string>

<string>河间,842</string>

<string>衡水,867</string>

<string>怀安,371</string>

<string>怀来,745</string>

<string>黄骅,852</string>

<string>鸡泽,860</string>

<string>临西,916</string>

<string>冀州,869</string>

<string>晋洲,444</string>

<string>井陉,448</string>

<string>景县,876</string>

<string>巨鹿,25</string>

<string>康保,345</string>

<string>宽城,762</string>

<string>涞源,409</string>

<string>廊坊,796</string>

<string>乐亭,815</string>

<string>蠡县,848</string>

<string>临城,19</string>

<string>临漳,483</string>

<string>灵寿,438</string>

<string>隆化,705</string>

<string>隆尧,20</string>

<string>卢龙,767</string>

<string>栾城,16</string>

<string>滦南,766</string>

<string>滦平,753</string>

<string>滦县,810</string>

<string>满城,839</string>

<string>孟村,861</string>

<string>内邱,23</string>

<string>南宫,870</string>

<string>南和,532</string>

<string>南皮,884</string>

<string>宁晋,22</string>

<string>邱县,934</string>

<string>平泉,706</string>

<string>平山,449</string>

<string>平乡,857</string>

<string>迁安,768</string>

<string>迁西,764</string>

<string>秦皇岛,769</string>

<string>青龙,765</string>

<string>青县,843</string>

<string>清河,871</string>

<string>曲阳,440</string>

<string>曲周,534</string>

<string>饶阳,834</string>

<string>任丘,838</string>

<string>容城,787</string>

<string>三河,800</string>

<string>沙河,8</string>

<string>尚义,346</string>

<string>涉县,528</string>

<string>深泽,849</string>

<string>深州,836</string>

<string>石家庄,453</string>

<string>顺平,408</string>

<string>肃宁,853</string>

<string>威县,915</string>

<string>唐海,814</string>

<string>唐山,813</string>

<string>唐县,447</string>

<string>万全,374</string>

<string>望都,835</string>

<string>围场,702</string>

<string>蔚县,406</string>

<string>魏县,537</string>

<string>文安,840</string>

<string>无极,454</string>

<string>吴桥,882</string>

<string>武安,531</string>

<string>武强,865</string>

<string>武邑,868</string>

<string>献县,845</string>

<string>香河,801</string>

<string>辛集,866</string>

<string>新河,858</string>

<string>新乐,450</string>

<string>兴隆,757</string>

<string>行唐,443</string>

<string>邢台,24</string>

<string>雄县,859</string>

<string>徐水,829</string>

<string>宣化,373</string>

<string>盐山,854</string>

<string>阳原,372</string>

<string>易县,790</string>

<string>永年,536</string>

<string>永清,799</string>

<string>玉田,802</string>

<string>元氏,18</string>

<string>赞皇,21</string>

<string>枣强,873</string>

<string>张北,347</string>

<string>张家口,743</string>

<string>赵县,11</string>

<string>正定,446</string>

<string>涿鹿,747</string>

<string>涿州,786</string>

<string>遵化,759</string>

<string>涞水,3441</string>

<string>鹿泉,3557</string>

<string>清苑,3558</string>

<string>定兴,3559</string>

<string>博野,3560</string>

<string>沧县,3561</string>

</ArrayOfString>

 (4) getWeather 获得天气预报数据

说明:输入参数:城市/地区ID或名称,

返回数据:一维字符串数组。

通过(2)(3)方法可以得到一个地区的代号ID,通过getWeather方法传入id参数即可得到该地区的天气数据:

例如:我想得到中国河北省张家口市尚义县(346)的天气数据:

      Url:http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/getWeather?theUserID=&theCityCode=346

返回数据结果:

<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://WebXml.com.cn/">

<string>河北张家口</string>

<string>尚义</string>

<string>346</string>

<string>2014/08/05 16:29:25</string>

<string>今日天气实况:气温:21;风向/风力:西北风 3级;湿度:33%</string>

<string>空气质量:暂无;紫外线强度:中等</string>

<string>

太阳镜指数:必要。建议佩戴透射比为1级的浅色太阳镜。穿衣指数:较舒适。建议穿薄外套或牛仔裤等服装。旅游指数:适宜。风稍大,但仍可尽情地享受大自然风光。运动指数:较适宜。推荐进行室内运动。洗车指数:较不宜。风力较大,洗车后会蒙上灰尘。化妆指数:去油。请选用露质面霜打底,水质无油粉底霜。感冒指数:极易发。温差极大,风力较强,极易感冒。空气污染指数:暂无。紫外线指数:中等。涂擦SPF大于15PA+防晒护肤品。舒适度指数:舒适。白天不冷不热,风力不大。

</string>

<string>85多云转晴</string>

<string>8/26</string>

<string>西北风4-5</string>

<string>1.gif</string>

<string>0.gif</string>

<string>86</string>

<string>9/24</string>

<string>西北风转西南风3-4</string>

<string>0.gif</string>

<string>0.gif</string>

<string>87多云</string>

<string>12/24</string>

<string>西南风3-4级转4-5</string>

<string>1.gif</string>

<string>1.gif</string>

<string>88多云</string>

<string>13/26</string>

<string>西南风4-5</string>

<string>1.gif</string>

<string>1.gif</string>

<string>89雷阵雨转多云</string>

<string>12/25</string>

<string>西南风3-4</string>

<string>4.gif</string>

<string>1.gif</string>

</ArrayOfString>

 

熟悉了接口的各个方法的使用后,在项目中通过URL打开连接获取数据,然后将天气数据进行处理即可。


本文出自 “索艳明” 博客,请务必保留此出处http://suoyanming.blog.51cto.com/6205176/1536041

java获取天气预报数据,布布扣,bubuko.com

java获取天气预报数据

标签:城市地区代号编码   天气预报   java获取天气预报接口   java获取天气预报数据   

原文地址:http://suoyanming.blog.51cto.com/6205176/1536041

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!