Return Yahoo! weather API data in Celsius, using YQL

前端 未结 3 773
长情又很酷
长情又很酷 2021-02-12 18:45

I\'m trying to get Yahoo! weather API with temperatures in Celsius.

I\'ve added &u=c in the request, but it\'s still returning data in Fahrenheit.

相关标签:
3条回答
  • 2021-02-12 19:05

    Whenever I had to call a temperature that I wanted in Celsius I just used a simple conversion function:

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

    Then again, I wanted to toggle between Fahrenheit and Celsius. Just calling the Celsius JSON element from Yahoo is probably better if all you want to use is Celsius.

    0 讨论(0)
  • 2021-02-12 19:07

    I used the yql

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

    and it worked fine with the results in Celsius. I changed the "LEXX0003" for the real WOEID of that zone and it seems to have worked.

    0 讨论(0)
  • 2021-02-12 19:14

    Better late than never...

    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=?";
    

    It's easier to read if you break it up. You we're pretty close, just needed the u=c as part of the query, not at the end of the url.

    0 讨论(0)
提交回复
热议问题