本文介绍了用于maxdistance和MongoDB的单位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使我了解MongoDB和地理空间搜索.基本上我想要的是用户能够查询的文档(图像)是在距用户当前位置一定距离内拍摄的.因此,我要搜索用户在距他站立的位置1公里以内拍摄的所有图像下面的示例,但我不知道将什么设置为最大距离值.

I am trying to get my head around MongoDB and geospatial searches.Basically what I want is for users to be able to query documents (images) thatare shot within a set distance from the users current location. So I the user is searching for all images that are shot within 1 km from where he is standing I try to use the below example but I have no idea what to set as the maxdistance value.

db.places.find({ loc : { $near : [50,50] , $maxDistance : 5 }})

所以我的问题是,如果我要搜索文档,应将maxdistance设置为什么?半径1公里之内?

So my question is what do I set as maxdistance if I am searching for documentswithin a 1 km radius?

我完全被困在这里.

推荐答案

为了在km范围内使用mongodb $near查询,您需要将半径值转换为km.默认情况下,mongodb $ near接受$maxDistance作为radius.

In order to use mongodb $near queries with km bounds, you need to convert the radius value to km. By default mongodb $near accepts $maxDistance as radius.

使用km时,将距离转换为111.12(一个度约为111.12公里),或者保持距离不变.

Convert distance by 111.12 (one degree is approximately 111.12 kilometers) when using km, or leave distance as it is on using degree

对您的问题

您可以使用此

   db.places.find( { loc : { $near : [50,50] , $maxDistance : 1/111.12 } } )

我已经回答了如何在此处使用 mongo地理空间特征详细信息.您可以签出

I have answered how to use mongo geospatial features here in detail. You can check out

这篇关于用于maxdistance和MongoDB的单位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 10:40