mongodb maxDistance的猫鼬单位 [英] mongodb mongoose unit of maxDistance
问题描述
在我的应用程序中,我正在尝试使用, RentModel.find({prop_location:{$ near:[msg.lat,msg.lng], $ maxDistance:500}},函数(错误,文档){} 我在数据库中只有一个值,其中纬度为 弗朗西斯科. 现在,
In my application, I am trying to use, RentModel.find({prop_location : { $near : [msg.lat, msg.lng], $maxDistance : 500}}, function(err, docs){} I have only one value in the database with latitude, longitude of san francisco. Now,
- 没有maxDistance时=>找出位置 完美的任何地方.
- 当我将maxDistance添加为5并在完全相同的位置进行搜索时 位置(具有相同的纬度,经度),则找不到 地点.
- 如果为50,则与第2点相同.
- 如果是500,我什至可以从伦敦找到位置.
- When there is no maxDistance => It finds out the location perfectly from anywhere.
- When I add maxDistance as 5 and search exactly at the same location (with same latitude, longitude), it does not find the location.
- If it is 50, same as point 2.
- If it is 500, I can even find the location from London.
怎么了?
距离的单位是多少? 我想找出5公里(公里)距离内的所有东西. db.executeCommand将解决我的问题吗?需要检查.
what is the unit of distance ? I want to find out everything within 5km (kilometer) distance. will db.executeCommand solve my problem ? need to check.
谢谢.
推荐答案
最后,我找到了解决问题的方法. 理论上,经度是x轴,纬度是y轴.但是我们习惯于纬度-经度而不是经度-纬度... 所以我搜索的方式是错误的
Finally I found the answer to my problem. Theoretically longitude is x-axis and latitude is y-axis. But we are used to latitude- longitude rather than longitude-latitude... So the way I was searching was wrong
$near : [msg.lat, msg.lng]
当我将其更改为 $ near:[msg.lng,msg.lat] 时,它甚至在5KM的情况下也开始工作...所以订购是问题所在.
When I changed this to $near : [msg.lng, msg.lat] , it started working even with 5KM... So ordering was the problem.
这篇关于mongodb maxDistance的猫鼬单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!