function beaufort(si,windspeed){ //console.log(si +" -"+ windspeed); var b = 0; mph = windspeed; if (si=='c') mph = mph * 1.609344; if (mph==0){b=0;} if ((mph>=1)&&(mph<3)){b=1;} if ((mph>=4)&&(mph<7)){b=2;} if ((mph>=8)&&(mph<12)){b=3;} if ((mph>=13)&&(mph<18)){b=4;} if ((mph>=19)&&(mph<24)){b=5;} if ((mph>=25)&&(mph<31)){b=6;} if ((mph>=32)&&(mph<38)){b=7;} if ((mph>=39)&&(mph<46)){b=8;} if ((mph>=47)&&(mph<54)){b=9;} if ((mph>=55)&&(mph<63)){b=10;} if ((mph>=64)&&(mph<72)){b=11;} if (mph>=73){b=12;} //console.log(mph +" -"+ b); return b; } function coloruvindex(uv){ if (uv<=2) color = "10bf00"; if ((uv>=3)&&(uv<=5)) color = "fff400"; if ((uv>=6)&&(uv<=7)) color = "ffab0a"; if ((uv>=8)&&(uv<=10)) color = "e11900"; if (uv>=11) color = "9324C6"; color = 'fff'; return color; } function getweatherinfo(id,lat,lon,si,lang){ // console.log(1); var wna = { "clear-day":"wi-day-sunny", "clear-night":"wi-night-clear", "rain":"wi-rain", "snow":"wi-snow", "sleet":"wi-sleet", "wind":"wi-cloudy-windy", "fog":"wi-fog", "cloudy":"wi-cloudy", "partly-cloudy-day":"wi-day-cloudy", "partly-cloudy-night":"wi-night-alt-cloudy", "hail":"wi-hail", "thunderstorm":"wi-thunderstorm", "tornado":"wi-tornado" }; var languages = ["ar","bs","de","el","en","es","fr","hr","hu","it","nl","pl","pt","ru","sk","sv","tet","tr","uk","x-pig-latin","zh-tw","zh"]; var unit = ''; var tempicon = ''; if (si=='f') { unit= 'us'; tempicon = 'fahrenheit'; } if (si=='c') { unit= 'si'; tempicon = 'celsius'; } //unit = 'auto'; lang = lang.toLowerCase(); var a = languages.indexOf(lang); var language = 'en'; if (a>0) language = lang; //console.log(a + language); $(function() { // var url = "//api.forecast.io/forecast/f07775805be1c71820c8fbdcabe9648a/"+lat+","+lon+ "?solar=1&units="+unit+"&lang="+language+"&exclude=alerts,flags&callback=?"; var url = "//api.darksky.net/forecast/f07775805be1c71820c8fbdcabe9648a/"+lat+","+lon+ "?solar=1&units="+unit+"&lang="+language+"&exclude=alerts,flags&callback=?"; //console.log(url); $.ajax({ url: url, dataType: 'json', async: false, success: function(data) { var html = ''; var html2 = ''; html += data.daily.summary; html += "
";
html += moment.unix(data.daily.data[i].time).format("ddd");
html += ' '; html += ""; html += ' '; // html += Math.round(data.daily.data[i].temperatureMin); // html += ' / '; html += Math.round(data.daily.data[i].temperatureMax); //html +=""; html += ' '; // html += ""; html += ' | ';
//https://erikflowers.github.io/weather-icons/
html2 += "
'; htmlnow += " "; htmlnow += ' | '; htmlnow += '';
htmlnow += " "+ Math.round(data.currently.temperature);
htmlnow += "°"+si.toUpperCase();
htmlnow += ' ';
htmlnow += ' | ';
htmlnow += '
';
/*
start UV-index
*/
var j = 0;
var maxuv = 0;
var maxuvstarttime = moment.tz((data.hourly.data[0].time )*1000, data.timezone);
var maxuvst = parseInt(maxuvstarttime.format("HH"));
while (j <= 23 ){
var maxuvtime = moment.tz((data.hourly.data[j].time )*1000, data.timezone);
var maxuvt = parseInt(maxuvtime.format("HH"));
if (maxuvt>=maxuvst){
if (maxuv '; htmlnow += " (now "; } htmlnow += data.currently.uvIndex; if (maxuv!=data.currently.uvIndex) { htmlnow += ")"; } /* end UV-index */ htmlnow += ''; htmlnow += ' | ';
htmlnow += '';
var cmt = moment.tz((data.daily.data[0].apparentTemperatureMinTime)*1000, data.timezone);
var mintime = cmt.format("h a");
var cmt2 = moment.tz((data.daily.data[0].apparentTemperatureMaxTime)*1000, data.timezone);
var maxtime = cmt2.format("h a");
htmlnow += Math.round(data.daily.data[0].apparentTemperatureMin);
htmlnow += ' - ';
htmlnow += Math.round(data.daily.data[0].apparentTemperatureMax);
htmlnow += "°"+si.toUpperCase();
// htmlnow += ' '; // htmlnow += "Windchill: "+ Math.round(data.currently.apparentTemperature); // htmlnow += "°"+si.toUpperCase(); htmlnow += ' | ';
htmlnow += '
'; htmlnow += " "; htmlnow += Math.round(data.currently.cloudCover*100) +"%"; htmlnow += ' | '; htmlnow += ''; htmlnow += " "; var windspeed = 0; if (si=='c') windspeed = Math.round((data.currently.windSpeed) *3.6) +" km/u"; if (si=='f') windspeed = Math.round(data.currently.windSpeed) + "mph"; htmlnow += windspeed; var b = beaufort(si,Math.round(data.currently.windSpeed) ); htmlnow += ""; htmlnow += ' | '; htmlnow += '
'; htmlnow += " "; htmlnow += Math.round(data.currently.humidity*100) +"%"; htmlnow += ' | '; htmlnow += ''; htmlnow += " "; htmlnow += Math.round(data.currently.pressure)+ " mb"; htmlnow += ' | '; htmlnow += '