MongoDB$GeoInner查询返回不正确的结果
集合架构:MongoDB$GeoInner查询返回不正确的结果,mongodb,mongodb-query,geospatial,Mongodb,Mongodb Query,Geospatial,集合架构: { "_id" : ObjectId("59629006d5idf90ed8013932"), "AssetNo" : "1", "location" : { "type" : "Point", "coordinates" : [ -79.33801, 35.31775 ] } 收藏索引: >db.temp.getIndexes() [ { "v" : 1, "
{
"_id" : ObjectId("59629006d5idf90ed8013932"),
"AssetNo" : "1",
"location" : {
"type" : "Point",
"coordinates" : [
-79.33801,
35.31775
]
}
收藏索引:
>db.temp.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "NearestNeighbor.temp"
},
{
"v" : 1,
"key" : {
"location" : "2dsphere"
},
"name" : "location_2dsphere",
"ns" : "NearestNeighbor.temp",
"2dsphereIndexVersion" : 2
}
]
查询:
db.temp.find({ "location" : { "$geoWithin" : { "$centerSphere" : [ [ -79.33519333 , 35.324] , 0.3 / 3963.2]}}})
此查询返回零个文档。两个坐标点之间的距离约为0.21英里。(我希望在半径为0.3英里的范围内找到点,上述文件最好位于球体/圆内)
这是我提到的查询格式:
db.<name>.find({
loc: { $geoWithin:
{
$centerSphere: [ [ long, lat ],
radius in MILES/3963.2 ] }
}
})
该文档将显示:
{ "_id" : ObjectId("59629006d5idf90ed8013932"), "AssetNo" : "1", "location" : { "type" : "Point", "coordinates" : [ -79.33801, 35.31775 ] } }
我尝试过调试,但找不到问题。有什么建议吗?GeoJSON对象以“米”为单位返回其距离,因此“英里”中有1609.34米。我计算错了两个lat-long坐标之间的距离。实际上是0.46英里,查询没有返回任何文档是正确的。这里的MongoDB文档说明centerSphere操作符使用英里作为示例(基本上地球半径需要在弧度转换的首选单位中)。这仅适用于距离“传统坐标对”的距离。在整个文档中还指出,GeoJSOn对象返回的距离以米为单位。@UmangDeora这仍然是一个问题,还是您已经解决了?GeoJSOn对象返回的距离以米为单位,因此一英里中有1609.34米。我计算错了两个lat-long坐标之间的距离。实际上是0.46英里,查询没有返回任何文档是正确的。这里的MongoDB文档说明centerSphere操作符使用英里作为示例(基本上地球半径需要在弧度转换的首选单位中)。这仅适用于距离“传统坐标对”的距离。在整个文档中,GeoJSOn对象以米为单位返回距离。@umagdeora这仍然是一个问题,还是您已经解决了?
{ "_id" : ObjectId("59629006d5idf90ed8013932"), "AssetNo" : "1", "location" : { "type" : "Point", "coordinates" : [ -79.33801, 35.31775 ] } }