Jak obliczyć temperaturę w celsjuszu openweathermap.org JSON?
Dostaję pogodę dla miasta za pomocą openweathermap.org.
Wywołanie jsonp działa i wszystko jest w porządku, ale wynikowy obiekt zawiera temperaturę w nieznanej jednostce:
{
//...
"main": {
"temp": 290.38, // What unit of measurement is this?
"pressure": 1005,
"humidity": 72,
"temp_min": 289.25,
"temp_max": 291.85
},
//...
}
Oto demo, które console.log
jest pełnym obiektem.
Nie wydaje mi się, aby otrzymana temperatura była w fahrenheicie, ponieważ konwersja 290.38
Fahrenheita na Celsjusza jest 143.544
.
Czy ktoś wie jaką jednostkę temperatury zwraca openweathermap?
4 answers
Wygląda jak kelvin . Konwersja Kelvina na Celsjusza jest łatwa: wystarczy odjąć 273,15.
I krótki rzut oka na Dokumentacja API mówi nam, że jeśli dodasz &units=metric
do swojego żądania, otrzymasz zwrot.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-20 12:34:10
To wygląda na kelvin, ale możesz określić format, który chcesz zwrócić dla temp, np.:
Http://api.openweathermap.org/data/2.5/weather?q=London&mode=json&units=metric
LUB
Http://api.openweathermap.org/data/2.5/weather?q=London&mode=json&units=imperial
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-20 12:36:29
Kelvin do Fahrenheita to:
(( kelvinValue - 273.15) * 9/5) + 32
Zauważyłem, że nie wszystkie wywołania OpenWeatherApp odczytują parametr units, jeśli został przekazany. (Przykład tego błędu: http://api.openweathermap.org/data/2.5/group?units=Imperial&id=5375480,4737316,4164138,5099133,4666102,5391811,5809844,5016108,4400860,4957280&appid=XXXXXX) Kelvin wciąż wraca.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-10-05 19:44:31
Możesz zmienić jednostkę na metryczną.
To jest mój kod.<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>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-11-15 15:01:51