我们可以使用$geoNear
从查询点到查询中两个或更多个地理点的距离吗?
Transport.aggregate([
{
$geoNear: {
near: first_route.origin.geocode,
spherical: true,
distanceField: "origin.distance",
key: "route.origin.geocode"
}
},
{ $match: query },
我将介绍这种情况。我有一个包含公交服务列表的文档集合,因此每个文档都将包含行程的详细信息,其中包含起点geopoint(A),终点geopoint(B),并且线串定义了路径以及开始时间。因此,用户可以通过指定起点(AU)和终点(BU)地理位置(使用Google API)来搜索公交车。我在这里查询总线的操作是,我使用turfjs缓冲用户选择的地理位置,并使用$geoIntersects
检查它是否与mongodb中的线串相交。现在我将得到从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
}