Jquery Openweathermap通过日出/日落或白天/夜晚获取图标
我有一个小功能:Jquery Openweathermap通过日出/日落或白天/夜晚获取图标,jquery,json,openweathermap,Jquery,Json,Openweathermap,我有一个小功能: function weather(){ $.getJSON("http://api.openweathermap.org/data/2.5/forecast/city?id=6551933&units=metric&lang=de&APPID=4649XXXXXXXXXXXXXXXX5b96",function(result){ $("#header .inside").append("<div id='weather'><di
function weather(){
$.getJSON("http://api.openweathermap.org/data/2.5/forecast/city?id=6551933&units=metric&lang=de&APPID=4649XXXXXXXXXXXXXXXX5b96",function(result){
$("#header .inside").append("<div id='weather'><div class='temp' style='background-image:url(/files/images/weather/" + result.list[0].weather[0].icon + ".png);'>" + Math.round(result.list[0].main.temp) + "°</div><div class='wind'>" + Math.round(result.list[0].wind.speed * 3.6) + "km/h</div></div>");
console.log("Weathericon: " + result.list[0].weather[0].icon);
console.log("Temperature: " + result.list[0].main.temp);
console.log("Wind: " + (result.list[0].wind.speed * 3.6) + " km/h");
});
}
函数weather(){
$.getJSON(“http://api.openweathermap.org/data/2.5/forecast/city?id=6551933&units=metric&lang=de&APPID=4649XXXXXXXXXXXXXXXX5b96,函数(结果){
$(“#header.inside”).append(“+Math.round(result.list[0].main.temp)+“°”+Math.round(result.list[0].wind.speed*3.6)+“km/h”);
console.log(“天气图标:+result.list[0].weather[0].icon”);
console.log(“温度:+result.list[0].main.temp”);
console.log(“风:+(结果列表[0]。风速*3.6)+“公里/小时”);
});
}
这很好用。只有一件事:当下午4点时,iconset将进入夜间。应该在日落时发生。日出时再换衣服
有人有想法吗?:)谢谢 你检查过城市ID是否正确了吗?也许给定的时间是本地的,这就是为什么你有一个滞后。是的,我肯定id 6551933是德国的Waabs。我有没有办法更改图标结果?像参数之类的?我不知道这个API,但您应该看看JSON响应中的sys:
sys.sunrise
和sys.sunset。可能是线索。你检查过城市ID是否正确吗?也许给定的时间是本地的,这就是为什么你有一个滞后。是的,我肯定id 6551933是德国的Waabs。我有没有办法更改图标结果?像参数之类的?我不知道这个API,但您应该看看JSON响应中的sys:sys.sunrise
和sys.sunset。可能是个线索。