OpenWeatherMap返回错误的当前天气

时间:2014-08-07 19:11:58

标签: json weather weather-api openweathermap

我正在尝试实现一个iPhone应用程序,我正在集成OpenWeatherMap来检索当前的天气。但是,我注意到返回的数据不正确(大约39华氏度)。

以下是我用于使用Lan / Lon坐标检索Denver,Usa当前天气的JSON URL,其中xxxxxxxxxxxxx是我的APPID密钥。

http://api.openweathermap.org/data/2.5/weather?APPID=xxxxxxxxxxxxx&lat=39.738539&lon=-104.981114

返回的温度为291.05988。从文档读取,这个温度单位是​​开尔文。所以为了转换为Fahrenhiet,我采取291.05988 - 254.928 = 36.13188华氏度。然而,真正的当前天气是75华氏度。这是约39度。

请告知我的错误。

由于 LOC

3 个答案:

答案 0 :(得分:8)

对于那些稍后巡航的人,您不需要为华氏做任何转换,您可以为您的请求添加另一个查询参数:

华氏度: units = imperial

...也是选项 摄氏度: units = metric

示例:

http://api.openweathermap.org/data/2.5/weather?q=London&appid=XXXXXX&units=imperial

找到此here

答案 1 :(得分:0)

如果您在帖子网址:&units=metric中使用,我发现了另一种方法,否则有必要创建可变的城市和钥匙:

city = 'London'
key = 'some_key'

所以它看起来像这样:

url = 'http://api.openweathermap.org/data/2.5/weather?q={}&appid={}&units=metric'.format(city,key)

答案 2 :(得分:-4)

我回答了我自己的问题......

我很天心相信OpenWeather写的评论,并且从Kelvin到Fahrenheit的计算都错了。来自OpenWeather's link here,它声明:

  

以开尔文为单位的温度。从这个数字减去273.15转换   到摄氏度。

该声明错误。要从Kelvin转换为Fahrenheit,请使用以下公式:

° F = 9/5(° K - 273) + 32

希望别人不会像我一样被这句话绊倒。