从openweathermap获取天气数据

时间:2016-11-04 12:22:50

标签: javascript openweathermap

如何获取JSON数据,雨,云等的温度? 名称normal返回,但其他参数不设防或错误。

http://jsbin.com/qayobod/edit?html,js,console,output

var app = angular.module('jsbin', []);

app.controller('DemoCtrl', function($http) {

    var vm = this;
    var temp1 = [];

    var URL = 'http://api.openweathermap.org/data/2.5/forecast/daily';

    var request = {
        method: 'GET',
        url: URL,
        params: {
            q: 'KansasCity',
            mode: 'json',
            units: 'imperial',
            cnt: '7',
            appid: '3ac1f68b653ffbf72a5f782420062771'
        }
    };

    $http(request).then(function(response) {
        vm.data = response.data;
        temp1[0] = angular.fromJson(response.data);
        console.log(temp1[0]);
        console.log(temp1[0].city.name);
        console.log(temp1[0].city.country);
        console.log(temp1[1].temp.day);
    }).catch(function(response) {
        vm.data = response.data;
    });
    console.log(temp);
});

0 个答案:

没有答案