I'm creating a web application in MEAN stack where books are donated and other users can accept these donations. This is the tutorial that I'm following. The details of the donations are stored in books table in the following manner:
{
{
"_id" : ObjectId("55d4410544c96d6f6578f893"),
latitude: 15.3705074,
longitude: 75.1355679,
"email" : "user111@gmail.com",
"name" : "user111",
"bookName" : "book1"
}
{
"_id" : ObjectId("58be6eb7e94fed1814f5757a"),
latitude: 15.3705074,
longitude: 75.1355679,
"email" : "user222@gmail.com",
"name" : "user222",
"bookName" : "book2"
}
{
"_id" : ObjectId("58be6a37e94fed1814f57579"),
latitude: 15.3705074,
longitude: 75.1355679,
"email" : "user333@gmail.com",
"name" : "user333",
"bookName" : "book3"
}
}
This is my controller file:
angular.module('showApp', []).controller('AppCtrl',['$scope','$timeout','$http', function($scope , $timeout, $http) {
$scope.getDonations = function(curLong, curLat){
$http.get('/books/').success(function(response){
$scope.books = response;
$scope.x = "";
//how can I calculate distance here using latitude and longitude from books table and display on the webpage?
});
};
}]);
The current location of the user are passed to the getDonations function. I'm having trouble in calculating the distance. I need to calculate the distance between the current user and the locations in every entry of books table and display the distance on the angular webpage so that the user can see the distance of the donations from his loaction.
angular code:`
<table>
<tr>
<td>Book Name</td>
<td>Donor's name</td>
<td>Email ID</td>
<td>Distamce</td>
</tr>
<tr ng-repeat="x in books">
<td></td>
<td></td>
<td></td>
<td> </td> //I need to display the distance here
</tr>
</table>
Please help me figure out how to do this. Thankyou :).
via Aishwarya
No comments:
Post a Comment