Flickr API - Get Image ID and pass to second request <p>I'm using Angular JS. My goal is to get a list of flickr images based on location and take the image IDs returned from the request and pass them into another request to get more information for each photo to be displayed in the results. Here is what I have but I can't seem to get the correct value returned from my second search function. Although this seems like a long question, I really just want to know how to get the correct value in my second function so I can assign it to my results. </p> <p>This is in my services.js</p> <pre><code>//flickr location search APIRequest.fkrSearch = function(lat, lon, rad){ fkrAPI = $resource('https://api.flickr.com/services/rest/?method=flickr.photos.search&amp;api_key=5956ffe850b325e0b121525800af5b31&amp;lat='+lat+'&amp;lon='+lon+'&amp;radius=5km&amp;format=json&amp;nojsoncallback=1', { dataType: 'jsonp', jsonp: 'jsoncallback' }); return fkrAPI.get().$promise.then(function (data){ console.log(data); return data; }); }; </code></pre> <p>Here is my request within my controller.</p> <pre><code>$scope.resultPosts = []; //global variable to hold results if ($scope.locationSearch.dataSource.fkr){ $scope.fkrLoading = true; console.log('search Flickr'); OSINTAPIRequest.fkrSearch($scope.lat, $scope.lng, $scope.radius).then(function(data){ if (data.error){ toastr.error(data.error.error_msg, 'Flickr Error['+data.error.error_code+']'); } else { if (data.photos.photo.length &gt; 0){ var fkrAppend = 0; for(var i=0; i &lt; data.photos.photo.length; i++){ fkrAppend++; var fkrImageId = data.photos.photo[i].id; $scope.resultPosts.push({ SourcePostID: data.photos.photo[i].id, Timestamp: '', PostLatitude: $scope.fkrGetLatLng(data.photos.photo[i].id), PostLongitude: $scope.fkrGetLatLng(data.photos.photo[i].id), PostMedia: 'https://farm'+data.photos.photo[i].farm+'.staticflickr.com/'+data.photos.photo[i].server+'/'+data.photos.photo[i].id+'_'+data.photos.photo[i].secret+'.jpg', PostType: 'image', PostAvatar: 'https://pingendo.github.io/pingendo-bootstrap/assets/user_placeholder.png', PostMarker: 'assets/img/fkrMarker.png', DataSource: 'flickr', Display:$scope.resultFilter.fkr }); } </code></pre> <p>This function returns a list of the image Ids for the photos geotagged in the give lat/long, but does not return the actual location data in the results for me to pass to the results and plot the point on the map. So you'll see that in my resultsPosts.push I'm trying to pass the returned image Id to the fkrGetLatLng function with this line <code>(PostLatitude: $scope.fkrGetLatLng(data.photos.photo[i].id))</code>... the function looks like this. </p> <pre><code>$scope.fkrGetLatLng = function (fkrImageId){ OSINTAPIRequest.fkrGetLatLong(fkrImageId).then(function(data){ var fkrLat = data.photo.location.latitude; var fkrLng = data.photo.location.latitude; //console.log (fkrLat+','+fkrLng); return fkrLat; }); } </code></pre> <p>And this is the request in the services JS. I'm getting the correct data back for each request, but it's not assigning the PostLatitude the correct value (or any value at all).</p> <pre><code> //flickr location search - get lat long APIRequest.fkrGetLatLong = function(fkrImageId){ fkrAPI = $resource('https://api.flickr.com/services/rest/?method=flickr.photos.geo.getLocation&amp;api_key=5956ffe850b325e0b121525800af5b31&amp;photo_id='+fkrImageId+'&amp;format=json&amp;nojsoncallback=1', { dataType: 'jsonp', jsonp: 'jsoncallback' }); return fkrAPI.get().$promise.then(function (data){ //console.log(data); return data; }); }; </code></pre>