Weather flickr search

This commit is contained in:
Max Lynch
2013-10-23 20:06:44 -05:00
parent ec9218a2c9
commit 2a4fe6099e
2 changed files with 25 additions and 8 deletions

View File

@ -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; 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) { this.getForecast = function(lat, lng) {
Weather.getForecast(lat, lng).then(function(resp) { Weather.getForecast(lat, lng).then(function(resp) {
console.log('Forecast', resp); console.log('Forecast', resp);
@ -22,6 +30,7 @@ angular.module('ionic.weather', ['ionic.weather.services', 'ionic.weather.direct
console.error(error); console.error(error);
}); });
}; };
this.getCurrent = function(lat, lng) { this.getCurrent = function(lat, lng) {
Weather.getAtLocation(lat, lng).then(function(resp) { Weather.getAtLocation(lat, lng).then(function(resp) {
$scope.current = resp.current_observation; $scope.current = resp.current_observation;
@ -34,8 +43,11 @@ angular.module('ionic.weather', ['ionic.weather.services', 'ionic.weather.direct
Geo.getLocation().then(function(position) { Geo.getLocation().then(function(position) {
console.log('GOT LAT', 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) { }, function(error) {
alert('Unable to get current location: ' + error); alert('Unable to get current location: ' + error);
}); });

View File

@ -19,10 +19,12 @@ angular.module('ionic.weather.services', ['ngResource'])
.factory('Flickr', function($q, $resource, FLICKR_API_KEY) { .factory('Flickr', function($q, $resource, FLICKR_API_KEY) {
var baseUrl = 'http://api.flickr.com/services/rest/' 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, safe_search: 1,
callback: 'JSON_CALLBACK', jsoncallback: 'JSON_CALLBACK',
api_key: FLICKR_API_KEY api_key: FLICKR_API_KEY,
format: 'json'
}, { }, {
get: { get: {
method: 'JSONP' method: 'JSONP'
@ -30,12 +32,15 @@ angular.module('ionic.weather.services', ['ngResource'])
}); });
return { return {
search: function(tags, lat, lng, cb) { search: function(tags, lat, lng) {
var q = $q.defer(); var q = $q.defer();
flickrSearch.get({ flickrSearch.get({
tags: tags,
lat: lat,
lng: lng
}, function(val) { }, function(val) {
q.resove(val); q.resolve(val);
}, function(httpResponse) { }, function(httpResponse) {
q.reject(httpResponse); q.reject(httpResponse);
}); });
@ -65,7 +70,7 @@ angular.module('ionic.weather.services', ['ngResource'])
}); });
return { return {
getForecast: function(lat, lng, cb) { getForecast: function(lat, lng) {
var q = $q.defer(); var q = $q.defer();
forecastResource.get({ forecastResource.get({