Попытка получить данные о погоде с помощью openweathermap.org
API. Согласно документации здесь. Я должен сделать звонок следующим образом:
api.openweathermap.org/data/2.5/weather?q={city name},{state}&appid={your api key}
Но я не могу найти город ни для одного города и штата, в которые вставляю.
{"cod":"404","message":"city not found"}
Вот как я попробовал это с моим сокращенным API:
Как правильно искать город. Конечная цель - получить json данные о погоде в городе для приложения ниже angularjs.
// module
var weatherApp = angular.module('weatherApp', ['ngRoute','ngResource']);
weatherApp.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'pages/home.html',
controller: 'homeController'
})
.when('/forecast', {
templateUrl: 'pages/forecast.html',
controller: 'forecastController'
})
});
// services
weatherApp.service('cityService', function(){
this.city = "New York,NY";
});
// controllers
weatherApp.controller('homeController', ['$scope', 'cityService',
function($scope, cityService) {
$scope.city = cityService.city;
$scope.$watch('city', function() {
cityService.city = $scope.city;
})
}]);
weatherApp.controller('forecastController', ['$scope', '$resource', 'cityService',
function($scope, $resource, cityService) {
$scope.city = cityService.city;
$scope.weatherAPI = $resource("http://api.openweathermap.org/data/2.5/weather", {
callback: "JSON_CALLBACK"}, {get: {method: "JSONP"}});
$scope.weatherResult = $scope.weatherAPI.get({ q: $scope.city, appid: "b...8e"});
console.log($scope.weatherResult);
}]);