I'm working with Angular, the ng-maps directive, and multiple social media APIs. First, I'm retrieving the data from the API, calculating whether it's in the search circle using google.maps.geometry.spherical.computeDistanceBetween(latLng, center) <= radius
which I got from this SO question (as well as this one) and then pushing it into an array containing the results which then plots the map markers onto the map.
I can't seem to get anything returned with the true value as the array is empty.
Here is the code:
$scope.radius = 1000;
$scope.lat = 48.0028;
$scope.lng = 37.8060;
$scope.searchCircle = {
position: [$scope.lat, $scope.lng],
radius: $scope.radius
};
$scope.mapSearch = function(){
if ($scope.vkLoading || $scope.igLoading || $scope.twtLoading) return;
$scope.resultPosts.length = 0;
console.log('Lat: '+$scope.lat+' Lng: '+$scope.lng+' Radius: '+$scope.radius+' Start: '+$scope.startDate+' End: '+$scope.endDate);
if ($scope.locationSearch.dataSource.vk){
$scope.vkLoading = true;
console.log('search Vk');
OSINTAPIRequest.vkSearch($scope.lat, $scope.lng, $filter('unixTimestamp')($scope.startDate, 'sec'), $filter('unixTimestamp')($scope.endDate, 'sec'),$scope.radius).then(function(data){
if (data.error){
toastr.error(data.error.error_msg, 'VkError['+data.error.error_code+']');
} else {
if (data.response.items.length > 0){
for(var i=0; i < data.response.items.length; i++){
/* Adjust for faulty radius */
$scope.markerPoints = [];
$scope.postLat = data.response.items[i].lat;
$scope.postLng = data.response.items[i].long;
$scope.postLatLng = [$scope.postLat,$scope.postLng];
$scope.markerPoints.push($scope.postLatLng);
if (google.maps.geometry.spherical.computeDistanceBetween($scope.markerPoints, $scope.searchCircle.position) <= $scope.radius) {
$scope.resultPosts.push({SourcePostID: data.response.items[i].id,
SourcePosterID : data.response.items[i].owner_id,
Timestamp : parseInt(data.response.items[i].date),
PostTitleTimestamp: $filter('timestamp')(data.response.items[i].date, 'title'),
PostTimestamp : $filter('timestamp')(data.response.items[i].date),
PostLatitude : data.response.items[i].lat,
PostLongitude : data.response.items[i].long,
PostMedia: data.response.items[i].photo_604,
PostContent: data.response.items[i].text,
PostType: 'image',
PostAvatar: 'https://pingendo.github.io/pingendo-bootstrap/assets/user_placeholder.png',
PostMarker: 'assets/img/vkMarker.png',
PostUsername : 'User ID ('+data.response.items[i].owner_id+')',
DataSource: 'vk'});
//console.log('Vk Timestamp: '+parseInt(data.response.items[i].date));
}
} else {
}
$scope.vkLoading = false;
}
}, function(error){
$scope.vkLoading = false;
console.log(error);
toastr.error('Unable to connect to server!','Server Error['+error.status+']');
});
}
I think I'm missing something extremely obvious and simple... any ideas as to what the issue is?
EDIT: here is the demo... http://plnkr.co/edit/3rO8K1j8GVXd8JyBzvrm?p=preview
when I add in the distance calculation (commented out) it doesn't add any markers to the array.