Java学习之利用yahoo weather api 获取天气预报
2011-07-24 16:47
549 查看
在cnblogs看到 狼の禅 写的Java获取yahoo天气预报一文,于是有了这篇文章。
狼の禅 是将<地点代码,地名> 对用HashMap 来保存在类中的,发现手动查找地点代码然后要一个个加进去还真麻烦,于是想下有没有偷懒的办法。果然,在雅虎 geoplanet 找到了答案。
最简单的办法是申请一个yahoo dev 的key ,然后就可以通过 GeoPlanet api 来查询相应地点的WOEID了。
狼の禅 用的是旧的p 参数传递地点代码,不过最新的api文档里面只对w参数作了说明,因此这里我就用WOEID了。
不想注册申请key,还是自己折腾吧。
下载最新的 GeoPlanet Data ,解压出来有这些个文件:
geoplanet_places_[version].tsv: the WOEID, the placename, and the WOEID of its parent entity
geoplanet_aliases_[version].tsv: alternate names in multiple languages indexed against the WOEID
geoplanet_adjacencies_[version].tsv: the entities neighboring each WOEID
geoplanet_changes_[version].tsv: the list of removed WOEIDs and their replacement WOEID mappings
这里我只取 geoplanet_places_7.6.0.tsv ,用EmEditor 打开,把 中国 地区的 COPY 出到另外一个文件Chinaplaces.tsv .
这个tsv 文件是用tab分隔字段的,places文件的字段有:
WOE_ID ISO Name Language PlaceType Parent_ID
View Code
本文参考文档:
Java获取yahoo天气预报
最初发布在:
http://ihacklog.com/?p=4684
狼の禅 是将<地点代码,地名> 对用HashMap 来保存在类中的,发现手动查找地点代码然后要一个个加进去还真麻烦,于是想下有没有偷懒的办法。果然,在雅虎 geoplanet 找到了答案。
最简单的办法是申请一个yahoo dev 的key ,然后就可以通过 GeoPlanet api 来查询相应地点的WOEID了。
狼の禅 用的是旧的p 参数传递地点代码,不过最新的api文档里面只对w参数作了说明,因此这里我就用WOEID了。
不想注册申请key,还是自己折腾吧。
下载最新的 GeoPlanet Data ,解压出来有这些个文件:
geoplanet_places_[version].tsv: the WOEID, the placename, and the WOEID of its parent entity
geoplanet_aliases_[version].tsv: alternate names in multiple languages indexed against the WOEID
geoplanet_adjacencies_[version].tsv: the entities neighboring each WOEID
geoplanet_changes_[version].tsv: the list of removed WOEIDs and their replacement WOEID mappings
这里我只取 geoplanet_places_7.6.0.tsv ,用EmEditor 打开,把 中国 地区的 COPY 出到另外一个文件Chinaplaces.tsv .
这个tsv 文件是用tab分隔字段的,places文件的字段有:
WOE_ID ISO Name Language PlaceType Parent_ID
View Code
package com.ihacklog.java.learn; import com.ihacklog.java.learn.GetWeatherInfo; /** * @author HuangYe <荒野无灯> * @URL http://ihacklog.com */ public class getWeather { public static void main(String arg[]) { // OK,let's begin the test. // Have fun! GetWeatherInfo info = new GetWeatherInfo(); String weather = info.getWeather("岳阳市"); System.out.println(weather); weather = info.getWeather("哈尔滨"); System.out.println(weather); weather = info.getWeather("海口市"); System.out.println(weather); weather = info.getWeather("长沙市"); System.out.println(weather); weather = info.getWeather("武汉市"); System.out.println(weather); } }
本文参考文档:
Java获取yahoo天气预报
最初发布在:
http://ihacklog.com/?p=4684
相关文章推荐
- Web Service学习笔记:利用YAHOO公开API做天气预报Web服务
- java 利用新浪天气API获取天气预报
- 利用免费weather service编写java天气预报客户端
- 『原创』WM利用Google Weather API获取天气预报
- Android(java)学习笔记193:利用谷歌API对数据库增删改查(推荐使用)
- 利用YAHOO公开API做天气预报Web服务
- Java调用yahoo!API获取天气数据
- JAVA通过API获取天气预报信息(HTTP协议)
- cURL使用之利用WeatherWebService获取天气预报
- JAVA基础 day22 File类的方法和应用 利用递归获取目录下的所有文件 Properties类的应用(和IO技术结合,存取配置文件) 打印流和合并流等功能类的学习应用 切割文件练习
- 利用java8 stream api 实现List集合分页获取工具
- java学习第十九天之API、Date、Calendar
- 利用百度API获取mp3及歌词lrc下载地址
- 利用JAVA获取网上信息
- JAVA学习第三十八课(常用对象API— Map集合及其常用方法
- Jquery学习笔记:利用parent和parents方法获取父节点
- java基础学习总结五(递归算法、冒泡排序、查看生成API)
- java学习日记_60:String类的获取功能
- JAVA学习笔记_利用slf4j进行log4j日志管理
- 学习日志---本地javaApi连接集群hdfs