2014-01-13 55 views
14

我試圖讓雅虎!天氣API,攝氏溫度。返回Yahoo!天氣API數據以攝氏度,使用YQL

我在請求中添加了&u=c,但它仍然以華氏溫度返回數據。

這是URL我正在使用:

http://query.yahooapis.com/v1/public/yql?q=select%20item%20from%20weather.forecast%20where%20location=%22LEXX0003%22&format=json&u=c

和響應:

{"query":{"count":1,"created":"2014-01-13T13:06:43Z","lang":"en-US","results":{"channel":{"item":{"title":"Conditions for Beirut, LE at 1:59 pm EET","lat":"33.82","long":"35.48","link":"http://us.rd.yahoo.com/dailynews/rss/weather/Beirut__LE/*http://weather.yahoo.com/forecast/LEXX0003_f.html","pubDate":"Mon, 13 Jan 2014 1:59 pm EET","condition":{"code":"30","date":"Mon, 13 Jan 2014 1:59 pm EET","temp":"64","text":"Partly Cloudy"},"description":"\n<img src=\"http://l.yimg.com/a/i/us/we/52/30.gif\"/><br />\n<b>Current Conditions:</b><br />\nPartly Cloudy, 64 F<BR />\n<BR /><b>Forecast:</b><BR />\nMon - Partly Cloudy. High: 64 Low: 55<br />\nTue - Cloudy. High: 66 Low: 56<br />\nWed - Mostly Sunny. High: 68 Low: 58<br />\nThu - Sunny. High: 70 Low: 60<br />\nFri - Scattered Showers. High: 65 Low: 57<br />\n<br />\n<a href=\"http://us.rd.yahoo.com/dailynews/rss/weather/Beirut__LE/*http://weather.yahoo.com/forecast/LEXX0003_f.html\">Full Forecast at Yahoo! Weather</a><BR/><BR/>\n(provided by <a href=\"http://www.weather.com\" >The Weather Channel</a>)<br/>\n","forecast":[{"code":"30","date":"13 Jan 2014","day":"Mon","high":"64","low":"55","text":"Partly Cloudy"},{"code":"26","date":"14 Jan 2014","day":"Tue","high":"66","low":"56","text":"Cloudy"},{"code":"34","date":"15 Jan 2014","day":"Wed","high":"68","low":"58","text":"Mostly Sunny"},{"code":"32","date":"16 Jan 2014","day":"Thu","high":"70","low":"60","text":"Sunny"},{"code":"39","date":"17 Jan 2014","day":"Fri","high":"65","low":"57","text":"Scattered Showers"}],"guid":{"isPermaLink":"false","content":"LEXX0003_2014_01_17_7_00_EET"}}}}}}` 

什麼想法?

+0

你有沒有解決這個工作的呢? – DanV

回答

53

好過從來沒有...

var locationQuery = escape("select item from weather.forecast where woeid in (select woeid from geo.places where text='GB-LND') and u='c'"), 
    locationUrl = "http://query.yahooapis.com/v1/public/yql?q=" + locationQuery + "&format=json&callback=?"; 

它很容易,如果你打破它讀取。我們非常接近,只需要將u = c作爲查詢的一部分,而不是在URL的末尾。

+0

如果我已經有和添加了什麼? Nil

+2

u ='c'不適合我...鋼材給我造成F –

+0

它的工作原理!謝謝 – nicmare

1

每當我不得不打電話給我在攝氏想我只是用一個簡單的轉換功能的溫度:

function FtoC(temp) {return Math.round((temp - 32)/(9/5));} 

再說,我想華氏度和攝氏度之間切換。只要調用雅虎的Celsius JSON元素,如果你想使用的只是Celsius,可能會更好。

6

我用YQL

select item from weather.forecast where woeid=22724447 and u='c' 

它工作得很好,在攝氏結果。我改變了「LEXX0003」爲該區域的真正WOEID,它似乎已經工作。

1

你可以試試這個:

YQL查詢:

select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="jiangmen,cn") and u="c" 

端點:

https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22jiangmen%2Ccn%22)%20and%20u%3D%22c%22&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys 

當我嘗試剛纔