小编sir*_*raj的帖子

MongoDB打印两点之间的距离

当我在MongoDB上触发此查询时,我将获得距离指定坐标500英里附近的所有位置.但我想知道指定坐标和结果位置之间的确切距离.

db.new_stores.find({ "geometry": { $nearSphere: { $geometry: { type: "Point", coordinates: [ -81.093699, 32.074673 ] }, $maxDistance: 500 * 3963 } } } ).pretty()
Run Code Online (Sandbox Code Playgroud)

我的输出看起来像:

{
    "_id" : ObjectId("565172058bc200b0db0f75b1"),
    "type" : "Feature",
    "geometry" : {
        "type" : "Point",
        "coordinates" : [
            -80.148826,
            25.941116
        ]
    },
    "properties" : {
        "Name" : "Anthony's Coal Fired Pizza",
        "Address" : "17901 Biscayne Blvd, Aventura, FL"
    }
}
Run Code Online (Sandbox Code Playgroud)

我也想知道这个地方与指定坐标的距离.我在几何上创建了2dsphere索引.

geospatial mongodb mongodb-query

14
推荐指数
2
解决办法
1万
查看次数

标签 统计

geospatial ×1

mongodb ×1

mongodb-query ×1