【发布时间】:2017-08-18 18:45:26
【问题描述】:
我正在构建一个 geolocationAPI,我正在尝试根据用户提交的最小和最大距离查询位置。但是,我无法在控制器中读取这些值。
我的意见:
<div class="form-group">
<label>Min Distance</label>
<input type="text" class="form-control text-center" ng-model="minDistance"><br>
</div>
<div class="form-group">
<label>Max Distance</label>
<input type="text" class="form-control text-center" ng-model="maxDistance"><br>
</div>
我试过这个,把它发送到控制器:
$scope.searchLocations = function () {
$scope.formData.minDistance = $scope.minDistance;
$scope.formData.maxDistance = $scope.maxDistance;
$http.get('/api/places')
.success(function (data) {
$scope.searchLocations = data;
//console.log($scope.formData.minDistance);
})
.error(function (data) {
console.log('Error: ' + data);
});
}
在我的控制器上我有这个:
exports.find_all_locations_near = function(req, res) {
if (req.body.minDistance > 0)
{
Location.find({
geolocation:
{
$near :
{
$geometry: { type: "Point", coordinates: [ lat, lon ] },
$minDistance: req.body.minDistance,
$maxDistance: req.body.maxDistance
}
}
}), function(err, location) {
if (err) {
//console.log(err);
res.send(err);
}
else if (location =='')
//res.json({ message: 'No location was found.' });
res.json({ message: 'No location was found.' });
else
{
res.json(location);
res.json({ message: 'The end.' });
}
};
} else
{
Location.find({}, function(err, location) {
if (err)
res.send(err);
res.json(location);
//res.json(req.body);
});
}
}
我想我不能这样使用 req.body ,对吧?我应该如何访问最小和最大距离的值?
【问题讨论】: