雅虎天气接口

广州天气

    https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid=2502265%20and%20u=%22c%22&format=json

雅虎天气接口

    查询时base_url:
https://query.yahooapis.com/v1/public/yql?q= , 公共查询接口,有限制查询次数
https://query.yahooapis.com/v1/yql?q= , 注册后获取ApkId,有限制查询次数但是已经足够使用了,10万次/天


第一步,手机端定位用户的位置(根据IP查询,或者。。。。),得到用户所在城市名称,或者城市名称的拼音,或者经纬度

第二步,根据用户所在城市的中文、英文、经纬度,获取woeid:


1,这里text键值可以用 中文、英文、经纬度。如


1): select * from geo.placefinder where text="Guangzhou"


2): select * from geo.placefinder where text="北京"


3): select * from geo.placefinder where text="39.9919336,116.3404132" and gflags = "R"


2,使用如下url查询城市的woeid:三种方法均可使用
https://query.yahooapis.com/v1/public/yql?q=select * from geo.placefinder where text="39.9919336,116.3404132" and gflags = "R"&format=json
https://query.yahooapis.com/v1/public/yql?q=select * from geo.placefinder where text="北京"&format=json
https://query.yahooapis.com/v1/public/yql?q=select * from geo.placefinder where text="Guangzhou"&format=json

注意使用经纬度获取woeid时一直取不到,后来才知道时缺少一个参数 fglags参数。,必须加 and gflags = "R"这一串才行

返回的xml格式的数据:
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:count="1" yahoo:created="2015-05-28T03:28:29Z" yahoo:lang="en-US">
<results>
<Result>
<quality>40</quality>
<latitude>23.12911</latitude>
<longitude>113.26336</longitude>
<offsetlat>23.12911</offsetlat>
<offsetlon>113.26336</offsetlon>
<radius>17700</radius>
<name/>
<line1/>
<line2>Guangzhou</line2>
<line3>Guangdong</line3>
<line4>People's Republic of China</line4>
<house/>
<street/>
<xstreet/>
<unittype/>
<unit/>
<postal/>
<neighborhood/>
<city>Guangzhou</city>
<county/>
<state>Guangdong</state>
<country>People's Republic of China</country>
<countrycode>CN</countrycode>
<statecode>44</statecode>
<countycode/>
<hash/>
<woeid>2161838</woeid> ,这个就是需要的woeid
<woetype>7</woetype>
</Result>
</results>
</query>
<!--  total: 11  -->
原文地址:https://www.cnblogs.com/jackyshan/p/5149127.html