hit*_*uct 38 javascript json units-of-measurement weather-api openweathermap
我正在使用openweathermap.org获取城市的天气.
jsonp调用正在运行,一切正常,但生成的对象包含未知单位的温度:
{
//...
"main": {
"temp": 290.38, // What unit of measurement is this?
"pressure": 1005,
"humidity": 72,
"temp_min": 289.25,
"temp_max": 291.85
},
//...
}
Run Code Online (Sandbox Code Playgroud)
这是一个console.log
完整对象的演示.
我不认为由此产生的温度是华氏温度,因为将290.38
华氏温度转换为摄氏温度143.544
.
有谁知道openweathermap返回的温度单位是多少?
T.J*_*der 108
它看起来像开尔文.将开尔文转换为摄氏温度很容易:只需减去273.15.
而简短的一瞥,在API文档告诉我们,如果你添加&units=metric
到你的要求,你会回来摄氏度.
开尔文换算华氏度为:
(( kelvinValue - 273.15) * 9/5) + 32
Run Code Online (Sandbox Code Playgroud)
我注意到并非所有 OpenWeatherApp 调用都会读取传入的单位参数。(此错误的示例: http://api.openweathermap.org/data/2.5/group?units=Imperial&id=5375480,4737316, 4164138,5099133,4666102,5391811,5809844,5016108,4400860,4957280&appid=XXXXXX ) 开尔文仍然返回。
归档时间: |
|
查看次数: |
33120 次 |
最近记录: |