цельсий = кельвин - 273.15
если я правильно понимаю и строка выводит температуру res.weather[0].main , то
pt>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 6,
center: {lat: 49.00, lng: 32.00}
});
var modal = document.getElementById('modal'),
res,
markerCoord,
marker,
markersArray = [],
infowindow,
contentString,
xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
google.maps.event.addListener(map, 'click', function (e) {
markerCoord = {lat: e.latLng.lat(), lng: e.latLng.lng()};
makeMarker();
// Get ajax call to get weather info
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == XMLHttpRequest.DONE ) {
if (xmlhttp.status == 200) {
res = JSON.parse(xmlhttp.responseText);
openModal(res);
}
else if (xmlhttp.status == 400) {
console.log('There was an error 400');
}
else {
console.log('something else other than 200 was returned');
}
}
};
xmlhttp.open("GET", "http://api.openweathermap.org/data/2.5/weather?lat=" + markerCoord.lat + "&lon=" + markerCoord.lng + '&apiKey=05d1a9582076e6fecf5c7a3a363b8328', true);
xmlhttp.send();
});
// Make clear all old markers and add new one
function makeMarker() {
for (var i in markersArray) {
markersArray[i].setMap(null);
}
markersArray.length = 0;
marker = new google.maps.Marker({
position: markerCoord,
map: map,
title: 'Weather here'
});
markersArray.push(marker);
}
function openModal(res) {
contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<div><b>Place: </b><span id="place"> ' + res.name + '</span> </div>'+
'<p><b>Weather:</b> <span id="weather">' +Math.round( res.weather[0].main - 273.15 )+ '</span></p>'+
'<p><b>Temp:</b> <span id="temp">' + res.main.temp +'</span>° K</p>'+
'<p><b>Wind speed:</b> <span id="wind">' + res.wind.speed + '</span> ms</p>'+
'<p><b>Humidity:</b> <span id="humidity">' + res.main.humidity + '</span>%</p>'+
'</div>';
infowindow = new google.maps.InfoWindow({
content: contentString
});
</pre> infowindow.open(map, marker);
}
}
</script>