为什么$ geoNear返回一个空对象?

时间:2020-03-21 07:40:17

标签: node.js geolocation geonear

我试图获取“点”与“开始位置”之间的距离,以显示“游览”的位置, 但是当我在邮递员中运行代码时,我得到了一个空对象

这是我的控制器

   exports.getDistances = catchAsync(async (req, res, next) => {
  const { latlng, unit } = req.params;
  const [lat, lng] = latlng.split(',');

  if (!lat || !lng) {
    next(
      new AppError(
        'Please provide latitute and longitude in the format lat,lng.',
        400
      )
    );
  }
  const distances = await Tour.aggregate([
    {
      $geoNear: {
        near: {
          type: 'Point',
          coordinates: [lng * 1, lat * 1]
        },
        distanceField: 'distance'
      }
    }
  ]);
  console.log(distances);
  res.status(200).json({
    status: 'success',
    data: {
      data: distances
    }
  });
});

0 个答案:

没有答案