按照Meteor中反应当前用户的距离对用户进行排序? [英] Sort users by distance from current user reactively in Meteor?

查看:74
本文介绍了按照Meteor中反应当前用户的距离对用户进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有已经面对问题在流星时根据各种数据处理出版物的被动排序。每一次,我从来没有找到真正的答案,我试图达到什么目的,最终我放弃了,只是决定不要以这种方式构建我的应用程序,这总让我非常难过。

现在也许我可以简单地说出这个问题,以便得到一个有建设性和非常有趣的答案。我认为这听起来像应该可以在Meteor应用程序中完成,所以这里是:

我存储我的位置用户在我的Accounts.users集合中的lat和lon变量。我希望当前用户获得他或她的10个最接近用户的列表。考虑到需要从经纬度得到这个距离的看起来很复杂的一系列操作,我该如何做到这一点?



据我所知,在MongoDB查询条件中插入这样的等式几乎是不可能的。那么,其他人如何实现这一壮举呢?



我希望对此问题有所了解,理论上可能如此。

解决方案

看看我的工作示例 localgeo 和来源 github



你可以像这样找到:

  var nearMarkers = allMarkers.find({
位置:{
$ near:{
$ geometry:{
type:Point,
coordinates:location
},
$ maxDistance:radius
}
}
} );

地点是 type 的MongoDB。请记住:在MongoDB Lng中 - 首先是Lat-second,我不知道为什么。我在客户端做这件事,但你可以用同样的方式发布,取决于半径。


I have already been facing issues in meteor when dealing with reactive sorting of a publication according to various data. Every time, I never found a real answer to what I was trying to achieve and I ended up giving up and just deciding "not to build my app that way", which always makes me really sad.

Now maybe I can phrase this problem simply enough that it could get a constructive and very interesting answer. I think it sounds like it should be possible to be done in a Meteor app, so here it is:

I store the locations of my users in "lat" and "lon" variables in my Accounts.users collection. I want the current user to get a list of, say, the 10 closest users to him or her. How would I do this, considering the seemingly complicated set of operations needed to get that distance from latitude and longitude?

As far as I know, it is pretty much impossible to insert such an equation in a MongoDB query condition. So how do other people achieve this feat?

I would appreciate any insight on this problem, as theoretical as it may be.

解决方案

Look at my working example localgeo and sources on github

You can find like this:

   var nearMarkers = allMarkers.find({
      location: {
        $near: {
          $geometry: {
            type: "Point",
            coordinates: location
          },
          $maxDistance: radius
        }
      }
    });

Location is this type of MongoDB. And remember: in MongoDB Lng - first, Lat - second, I don't know why. I do it on client side, but you can make publication in the same way, depend on radius.

这篇关于按照Meteor中反应当前用户的距离对用户进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆