programing

openweathermap.org JSON에서 반환되는 온도(섭씨)는 어떻게 계산합니까?

codeshow 2023. 3. 18. 09:10
반응형

openweathermap.org JSON에서 반환되는 온도(섭씨)는 어떻게 계산합니까?

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
    },
    //...
}

여기 데모가 있습니다.console.log는 완전한 오브젝트입니다.

화씨로 환산하면 온도가 화씨로 나오지는 않을 겁니다290.38화씨에서 섭씨까지는143.544.

몇 도 단위 노천일기 지도가 돌아오는지 아는 사람 있나요?

켈빈처럼 생겼네.켈빈을 섭씨로 변환하는 것은 쉽다: 273.15를 빼면 된다.

API 매뉴얼을 참조하는 중&units=metric당신의 요청에 따라 섭씨로 돌아갑니다.

이는 켈빈으로 보이지만 다음과 같이 temp에 대해 반환할 형식을 지정할 수 있습니다.

http://api.openweathermap.org/data/2.5/weather?q=London&mode=json&units=metric

또는

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

켈빈에서 화씨:

(( 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) Kelvin은 여전히 반환됩니다).

단위를 미터법으로 변경할 수 있습니다.

이건 내 암호야

<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>

먼저 원하는 포맷을 결정합니다.BASE_URL로 city를 전송한 후 &mode=json&module=module만 추가합니다.서버에서 정확한 섭씨 값을 얻을 수 있습니다.

이 예시를 사용해 보세요.

curl --location --request GET 'http://api.openweathermap.org/data/2.5/weather?q=Manaus,br&APPID=your_api_key&lang=PT&units=metric'

언급URL : https://stackoverflow.com/questions/19477324/how-do-i-calculate-the-temperature-in-celsius-returned-in-openweathermap-org-jso

반응형