【发布时间】:2018-12-04 14:46:09
【问题描述】:
我有 [lat, lon] 对存储在 MongoDb 中的不同位置。现在我想按距离比较某个坐标对,例如距离该点 2 公里 的圆圈,并希望从数据库中获取所有结果。
【问题讨论】:
标签: node.js mongodb google-maps gis geojson
我有 [lat, lon] 对存储在 MongoDb 中的不同位置。现在我想按距离比较某个坐标对,例如距离该点 2 公里 的圆圈,并希望从数据库中获取所有结果。
【问题讨论】:
标签: node.js mongodb google-maps gis geojson
你应该看看geoNear 命令。
通用示例如下:
db.runCommand(
{
geoNear: "places", // Your target collection
near: { type: "Point", coordinates: [ -73.9667, 40.78 ] }, // Point coordinates
spherical: true, // 2dsphere index required for using this option
query: { yourField: "someFilterVale" }, // Additional regular filtering
maxDistance: 2000 // Maximum distance in meters/radians
}
)
minDistance也可以查询
还有一个$geoNear 聚合。
【讨论】: