gpt4 book ai didi

MongoDB geoNear 多坐标

转载 作者:可可西里 更新时间:2023-11-01 10:01:28 28 4
gpt4 key购买 nike

我想根据它们与 2D 空间中多个点的接近程度对我的结果进行排序。

我假设这将通过查询第一点然后根据第二点重新查询/检查这些结果来完成?

也许下面的代码可以更好地解释我想要实现的目标?

db.runCommand({
geoNear:"places",
near:[ [52.5243, 13.4063], [48.1448, 11.5580] ]
})

解决方案:如果有人感兴趣,我就是这样实现的(感谢下面的答案)

a = Trip.geo_near([52.5243, 13.4063], :max_distance => 40, :unit => :mi).uniq
b = Trip.geo_near([48.1448, 11.5580], :max_distance => 40, :unit => :mi).uniq
@results = a & b

最佳答案

MongoDB 在其文档中有一整节是关于地理空间索引的。 http://www.mongodb.org/display/DOCS/Geospatial+Indexing

我认为您正在寻找的是边界框查询。这直接来自他们的代码示例。

box = [[40.73083, -73.99756], [40.741404,  -73.988135]]
db.places.find({"loc" : {"$within" : {"$box" : box}}})

关于MongoDB geoNear 多坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9723258/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com