【问题标题】:Find places based on place radius, not user radius in MongoDB根据地点半径查找地点,而不是 MongoDB 中的用户半径
【发布时间】:2015-05-13 05:41:39
【问题描述】:

我需要按照跟图一样的方式找地方。

我的收藏是:

{
    name: "Mc Donalds",
    location: { 
        "type": "Circle",
        "coordinates": [100,0],
        "radius": 20
    }
}

没有成功,我尝试使用以下代码进行搜索:

db.places.find({
    location: {
        $geoIntersects: {
            $geometry: {
                type: "Point",
                coordinates: [ 110, 10]
            }
        }
    }
})

如何获取一个Point所在的所有圆,如图所示?

【问题讨论】:

    标签: mongodb gps geolocation geojson


    【解决方案1】:

    您想让所有餐厅都在 Point 110,10 附近 - 所以圈内一次

    db.runCommand({ 
    "geoNear" : "places", 
    "near" : { "type" : "Point" , "coordinates" : [110, 10] },
    "spherical" : true, 
    "distanceMultiplier" : 0.001,
    query: { "category": "restaurants" }
    })
    

    geoNear 按距离对文档进行排序。您可以使用 minDistance / maxDistance 参数或相应地对结果集进行分组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-08
      • 2013-09-12
      • 2017-08-05
      • 2017-01-16
      • 1970-01-01
      相关资源
      最近更新 更多