2016-03-24 10 views
0

Bu api'yi kullanıyorum: http://openweathermap.org/api ama ertesi gün ertesi gün ve sonraki gün için nasıl veri alabilirim bilmiyorum. Hangi parametreleri kullanabileceğimi ve nasıl kullanılacağını önerin?Bugün için hava, gün ve sonraki gün için veri nasıl alınır?

böyle uğraş ama ben kaybolmak: Call 16 day/daily forecast data:

var weatherUrl = 'http://api.openweathermap.org/data/2.5/forecast?q=Zurich&APPID=08dbab0eeefe53317d2e0ad7c2a2e060&units=metric'; 
     $.getJSON(
     encodeURI(weatherUrl), 
     function(data) { 

      if(data !== null && data.list !== null) { 
      var result = data, 
       weather = {}, 
       compass = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N'], 
       image404 = 'https://s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png'; 
       console.log(result); 
       for(var i = 0; i < result.list.length; i++){ 
       weather.temp = Math.round(result.list[i].main.temp); 

       weather.code = result.list[i].weather[0].id; 

       weather.text = ucfirst(result.list[i].weather[0].description); 
       weather.date = result.dt_txt; 
      } 

      options.success(weather); 
      } else { 
      options.error('There was a problem retrieving the latest weather information.'); 
      } 
     } 
    ); 

cevap

1

göz at. Burada kodunuz ihtiyaçlarınıza göre düzenlenmiştir.

function ucfirst(str) { 
 
    var firstLetter = str.slice(0, 1); 
 
    return firstLetter.toUpperCase() + str.substring(1); 
 
} 
 

 
var weatherUrl = 'http://api.openweathermap.org/data/2.5/forecast/daily?q=Zurich&APPID=APP_ID&units=metric'; 
 
$.getJSON(
 
    encodeURI(weatherUrl), 
 
    function (data) { 
 

 
     if (data !== null && data.list !== null) { 
 
      var result = data, 
 
       weather = {}, 
 
       compass = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N'], 
 
       image404 = 'https://s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png'; 
 
      console.log(result); 
 
      var weathers = []; 
 
      for (var i = 0; i < 3; i++) { 
 
       weathers.push({ 
 
        temp: Math.round(result.list[i].temp.day), 
 
        code: result.list[i].weather[0].id, 
 
        text: ucfirst(result.list[i].weather[0].description), 
 
        date: new Date(result.list[i].dt * 1000) 
 
       }); 
 
      } 
 
      console.log(weathers); 
 
      var today = weathers[0]; 
 
      var tomorrow = weathers[1]; 
 
      var dayAfterTomorrow = weathers[2]; 
 
     } else { 
 
      console.log('There was a problem retrieving the latest weather information.'); 
 
     } 
 
    } 
 
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

+0

thats .... tnx :) – None

+0

@Meiko sizin kod parçacığı çalışmıyor. –

+0

@ankitsuthar plz, "weatherUrl" öğesindeki "APPID" öğesini APPID değerinize değiştirin –