0

我们可以使用$geoNearfrom query point 在查询中找到到两个或多个地理点的距离吗?

 Transport.aggregate([
    {
        $geoNear: {
            near: first_route.origin.geocode,
            spherical: true,
            distanceField: "origin.distance",
            key: "route.origin.geocode"
        }
    },
 { $match: query },

我将讲述这个场景。我有一个包含公共汽车服务列表的文档集合,因此每个文档都将包含行程的详细信息,包括起点地理点(A)、终点地理点(B)和一个线串定义路径以及开始时间。因此,用户可以通过给出开始(AU)和结束(BU)地理点(使用google api)来搜索公共汽车。我在这里查询总线的是我使用 turfjs 缓冲用户选择的地理点并检查它是否与 mongodb 中的线串相交$geoIntersects. 现在我将得到从 A 到 B 和 B 到 A 的巴士作为结果,我想从结果中过滤掉 B 到 A(用户可以在实际巴士路线之间搜索子路线)。为此,我想找到从巴士的起点(A)到“用户(AU)的起点”和“用户(BU)选择的终点”的距离,从这些距离中我总是可以确保 A-AU 更小比 A-BU 过滤掉从 B 到 A 的总线。文档如下所示,我删除了一些坐标以减少数据长度。我更喜欢逻辑建议来克服这个问题。

{
    "_id": "5bb21fe97c877c39e0bbc694",
    "route": {
        "origin": {
            "geocode": {
                "type": "Point",
                "coordinates": [
                    10.0601903,
                    76.6350827
                ]
            },
            "geocode_buffered": {
                "type": "Polygon",
                "coordinates": [
                    [  ]
                ]
            },
            "place": "Kothamangalam, Kerala, India",
            "place_id": "ChIJqY5hYBLmBzsRB1zUid9GIqM"
        },
        "destination": {
            "geocode": {
                "type": "Point",
                "coordinates": [
                    9.9894229,
                    76.57897490000005
                ]
            },
            "geocode_buffered": {
                "type": "Polygon",
                "coordinates": [
                    [ ]
                ]
            },
            "place": "Muvattupuzha, Kerala, India",
            "place_id": "ChIJ8_D2nYzdBzsR5WJwzP9sULQ"
        },
        "geocodes": {
            "type": "LineString",
            "coordinates": [
                [
                    10.06028,
                    76.63511000000001
                ],
                [
                    10.06042,
                    76.6346
                ],
                [
                    10.060490000000001,
                    76.63411
                ], 
                [
                    9.989220000000001,
                    76.58159
                ], 
                [
                    9.989450000000001,
                    76.5794
                ],
                [
                    9.98943,
                    76.57932000000001
                ],
                [
                    9.98935,
                    76.57905000000001
                ]
            ]
        },
        "route_index": 0,
        "route_name": "NH85" 
    },
    "access_type": "public",
    "type": "bus",
    "day_frequency": [
        1,
        2,
        3,
        4,
        5,
        6,
        7
    ],
    "duration_days": 0,
    "duration_hours": 0.23,
    "created_on": "2018-10-01T13:20:26.006Z",
    "title": "Rx100",
    "description": "Ls",
    "timings": [
        {
            "departure": "13:00",
            "destination": "13:23",
            "_id": "5bb21fe97c877c39e0bbc692",
            "trackings": []
        }
    ], 
    "__v": 0
}

4

0 回答 0