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)은 "국제 단위 시스템"의 온도 단위입니다. 그것은 물리학에 기초하여 절대적입니다. 0은 "절대 0"입니다. 그것은 나를위한 "기본"에 대한 아주 자연스러운 선택으로 보입니다 ... – MarcoS

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>