gpt4 book ai didi

ruby-on-rails - 使用 Mongoid Model.in 方法的最大距离

转载 作者:可可西里 更新时间:2023-11-01 09:07:26 25 4
gpt4 key购买 nike

我使用 geo near 查询已有一段时间了,但我似乎无法弄清楚如何将结果限制在特定半径内。例如,如何在这个查询中将搜索范围限制在 20 英里以内?

Place.near(:coordinates => location.reverse) 
# must reverse the resulting coordinates array because mongo stores them backwards [lng,lat]

最佳答案

南北纬度差的弧度长度,在任何纬度上约为60海里、111公里或69法定英里;您可以阅读更多关于 here in wikipedia 的信息或在 mongo 地理空间页面 The Earth is Round but Maps are Flat .

分别使用英里或公里时将距离除以69或111,所以现在您可以这样查询

Place.where(:coordinates => {"$near" => location.reverse , '$maxDistance' => 20.fdiv(69)})

关于ruby-on-rails - 使用 Mongoid Model.in 方法的最大距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7848634/

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