Utilizing Angular JS, my objective involves retrieving a list of Flickr images based on location. The image IDs obtained from the initial request need to be passed into another request to gather additional information for each photo displayed in the results. Despite my efforts, I am encountering difficulties with obtaining the correct value from the second search function. While the question may seem lengthy, all I really need help with is acquiring the accurate value within my second function so that it can be assigned to the results.
The code snippet below resides in my services.js file:
//flickr location search
APIRequest.fkrSearch = function(lat, lon, rad){
fkrAPI = $resource('https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=5956ffe850b325e0b121525800af5b31&lat='+lat+'&lon='+lon+'&radius=5km&format=json&nojsoncallback=1', { dataType: 'jsonp', jsonp: 'jsoncallback' });
return fkrAPI.get().$promise.then(function (data){
console.log(data);
return data;
});
};
Here is the corresponding request within my controller:
$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 > 0){
var fkrAppend = 0;
for(var i=0; i < 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
});
}
In this scenario, the fkrGetLatLng function returns a list of image IDs for geotagged photos at the specified latitude and longitude but fails to provide actual location data in the results necessary for plotting points on the map. The line
(PostLatitude: $scope.fkrGetLatLng(data.photos.photo[i].id))
attempts to pass the returned image ID to the fkrGetLatLng function, which is structured as follows:
$scope.fkrGetLatLng = function (fkrImageId){
OSINTAPIRequest.fkrGetLatLong(fkrImageId).then(function(data){
var fkrLat = data.photo.location.latitude;
var fkrLng = data.photo.location.longitude;
//console.log (fkrLat+','+fkrLng);
return fkrLat;
});
}
The following section covers the request contained within the services JS, where both requests yield correct data but encounter issues assigning the PostLatitude field the appropriate value:
//flickr location search - get lat long
APIRequest.fkrGetLatLong = function(fkrImageId){
fkrAPI = $resource('https://api.flickr.com/services/rest/?method=flickr.photos.geo.getLocation&api_key=5956ffe850b325e0b121525800af5b31&photo_id='+fkrImageId+'&format=json&nojsoncallback=1', { dataType: 'jsonp', jsonp: 'jsoncallback' });
return fkrAPI.get().$promise.then(function (data){
//console.log(data);
return data;
});
};