From 2a4fe6099e06811f4e156eddbd35b7edbd7d1660 Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Wed, 23 Oct 2013 20:06:44 -0500 Subject: [PATCH] Weather flickr search --- starters/weather/app.js | 16 ++++++++++++++-- starters/weather/services.js | 17 +++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/starters/weather/app.js b/starters/weather/app.js index 221c817d17..ea365e103c 100644 --- a/starters/weather/app.js +++ b/starters/weather/app.js @@ -10,9 +10,17 @@ angular.module('ionic.weather', ['ionic.weather.services', 'ionic.weather.direct }; }) -.controller('WeatherCtrl', function($scope, Weather, Geo) { +.controller('WeatherCtrl', function($scope, Weather, Geo, Flickr) { var _this = this; + this.getBackgroundImage = function(lat, lng) { + Flickr.search('sunset', lat, lng).then(function(resp) { + console.log('FLICKR', resp); + }, function(error) { + console.error('Unable to get Flickr images', error); + }); + }; + this.getForecast = function(lat, lng) { Weather.getForecast(lat, lng).then(function(resp) { console.log('Forecast', resp); @@ -22,6 +30,7 @@ angular.module('ionic.weather', ['ionic.weather.services', 'ionic.weather.direct console.error(error); }); }; + this.getCurrent = function(lat, lng) { Weather.getAtLocation(lat, lng).then(function(resp) { $scope.current = resp.current_observation; @@ -34,8 +43,11 @@ angular.module('ionic.weather', ['ionic.weather.services', 'ionic.weather.direct Geo.getLocation().then(function(position) { console.log('GOT LAT', position); + var lat = position.coords.latitude; + var lng = position.coords.longitude; - _this.getCurrent(position.coords.latitude, position.coords.longitude); + _this.getBackgroundImage(lat, lng); + _this.getCurrent(lat, lng); }, function(error) { alert('Unable to get current location: ' + error); }); diff --git a/starters/weather/services.js b/starters/weather/services.js index bb52061f6c..b0b57de9e4 100644 --- a/starters/weather/services.js +++ b/starters/weather/services.js @@ -19,10 +19,12 @@ angular.module('ionic.weather.services', ['ngResource']) .factory('Flickr', function($q, $resource, FLICKR_API_KEY) { var baseUrl = 'http://api.flickr.com/services/rest/' - var flickrSearch = $resource(baseUrl + '?method=flickr.photos.search', { + var flickrSearch = $resource(baseUrl, { + method: 'flickr.photos.search', safe_search: 1, - callback: 'JSON_CALLBACK', - api_key: FLICKR_API_KEY + jsoncallback: 'JSON_CALLBACK', + api_key: FLICKR_API_KEY, + format: 'json' }, { get: { method: 'JSONP' @@ -30,12 +32,15 @@ angular.module('ionic.weather.services', ['ngResource']) }); return { - search: function(tags, lat, lng, cb) { + search: function(tags, lat, lng) { var q = $q.defer(); flickrSearch.get({ + tags: tags, + lat: lat, + lng: lng }, function(val) { - q.resove(val); + q.resolve(val); }, function(httpResponse) { q.reject(httpResponse); }); @@ -65,7 +70,7 @@ angular.module('ionic.weather.services', ['ngResource']) }); return { - getForecast: function(lat, lng, cb) { + getForecast: function(lat, lng) { var q = $q.defer(); forecastResource.get({