mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-07 06:57:02 +08:00
Weather flickr search
This commit is contained in:
@ -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);
|
||||
});
|
||||
|
||||
@ -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({
|
||||
|
||||
Reference in New Issue
Block a user