23

私はopenweathermap.orgを使って都市の天気を得ています。openweathermap.orgで返される摂氏温度をどのように計算するのですか?JSON?

JSONPコールが働いているとすべてが正常であるが、結果のオブジェクトは、未知のユニット内の温度が含まれています。ここでは

{ 
    //... 
    "main": { 
     "temp": 290.38, // What unit of measurement is this? 
     "pressure": 1005, 
     "humidity": 72, 
     "temp_min": 289.25, 
     "temp_max": 291.85 
    }, 
    //... 
} 

はデモ console.logの完全なオブジェクトです。

華氏290.38を摂氏に変換すると、143.544になるため、結果的に気温が華氏になるとは思われません。

openweathermapが返す温度単位は誰にも分かりますか?

答えて

75

kelvinのように見えます。ケルビンを摂氏に変換するのは簡単です:273.15を引くだけです。

そしてthe API documentation最も簡潔一目は、あなたがあなたの要求に&units=metricを追加した場合、あなたが戻って、摂氏を取得しますことを教えてくれる。ケルビンように見えますが、あなたは例えば、あなたが一時に返さする形式を指定することができ

+0

@TJCrowder @TJCrowder @TJCrowderそれほど奇妙なデフォルトはありませんか? – hitautodestruct

+3

@hitautodestruct:それは* me *ですが、私は科学者ではありません。 :-) –

+4

ケルビン(http://en.wikipedia.org/wiki/Kelvin)は、「国際単位系」の温度単位です。物理学に基づいて絶対的です。ゼロは「絶対ゼロ」です。それは私にとっては、 "デフォルト"のための非常に自然な選択のように見える... – MarcoS

6
+0

お時間をいただきありがとうございます! – hitautodestruct

+0

@spacebeanこれは次のようなエラーを表示しています: '{" cod ":401、" message ":"無効なAPIキーです。詳細はhttp://openweathermap.org/faq#error401を参照してください。 –

1

は次のとおりです。

((kelvinValue - 273.15) * 9/5) + 32 

私が気づいたのは、OpenWeatherAppのすべての呼び出しが、渡された場合にunitsパラメーターを読み取ったわけではありません。 (このエラーの例: http://api.openweathermap.org/data/2.5/group?units=Imperial&id=5375480,4737316,4164138,5099133,4666102,5391811,5809844,5016108,4400860,4957280&appid=XXXXXX) ケルビンは依然として返されます。

1

単位をメートル法に変更することができます。

これは私のコードです。

<head> 
    <script src="http://code.jquery.com/jquery-1.6.1.min.js"></script> 
     <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.min.js"></script> 
     <style type="text/css">] 
     body{ 
      font-size: 100px; 

     } 

     #weatherLocation{ 

      font-size: 40px; 
     } 
     </style> 
     </head> 
     <body> 
<div id="weatherLocation">Click for weather</div> 

<div id="location"><input type="text" name="location"></div> 

<div class="showHumidity"></div> 

<div class="showTemp"></div> 

<script type="text/javascript"> 
$(document).ready(function() { 
    $('#weatherLocation').click(function() { 
    var city = $('input:text').val(); 
    let request = new XMLHttpRequest(); 
    let url = `http://api.openweathermap.org/data/2.5/weather?q=${city}&units=metric&appid=[YOUR API KEY HERE]`; 


    request.onreadystatechange = function() { 
     if (this.readyState === 4 && this.status === 200) { 
     let response = JSON.parse(this.responseText); 
     getElements(response); 
     } 
    } 

    request.open("GET", url, true); 
    request.send(); 

    getElements = function(response) { 
     $('.showHumidity').text(`The humidity in ${city} is ${response.main.humidity}%`); 
     $('.showTemp').text(`The temperature in Celcius is ${response.main.temp} degrees.`); 
    } 
    }); 
}); 
</script> 

</body> 
関連する問題