本文介绍了使用2个Google地图点(经度和纬度)从mongodb Query中查找平方面积数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究mongodb地理空间功能.

I am working on mongodb Geospatial feature.

以下是我的数据库架构

{
    _id:5c6fea5aa7f54038cc63db92,
    location:{
        coordinates:[-96.81916,33.07516],
        type:"Point"
    },
    userId:1
}

我有2个点,每个点都有经度和纬度,其示例在下面

I have 2 point and each one have latitude and longitude and its example is below

ne_latitude :32.789133220783015 ne_longitude :-96.67529208374026

ne_latitude: 32.789133220783015 ne_longitude: -96.67529208374026

基于这2个点,我需要获取所有在这2个点的正方形中覆盖的userId

base on these 2 points i need to get all userId which are cover in these 2 points square

您能建议我给我结果的mongo查询吗?

Can you please suggest me mongo query which give me result?

推荐答案

我尝试了很多方法,最后得到了一个解决方法

I tried many way and finally i got one solution

解决方案1的步骤:

第1步:从这2个点找到边界

Step 1: find boundary from that 2 point

第2步:使用来自地理空间的$ box(参考: $ box from mongo ),然后在其中传递该边界点.

Step 2: use $box from Geospatial (ref: $box from mongo) and pass this boundary point in that..

{    location: { 
       $geoWithin: { 
           $box:  [ [ 32.740776, 32.8112099 ], [ -96.910983, -96.683016 ] ] 
        }     
      } 
}

解决方案2的步骤

步骤1:按照以下方式正确设置现有点

Step 1: setup existing point proper way as following

第2步:使用来自地理空间的$ box(参考: $ box from mongo ),然后在其中传递该边界点.

Step 2: use $box from Geospatial (ref: $box from mongo) and pass this boundary point in that..

{    location: { 
       $geoWithin: { 
           $box:  [ [ 32.76286484066411,  32.789133220783015 ], [ -96.91870791625979, -96.67529208374026 ] ] 
        }     
      } 
}

希望对您有帮助

这篇关于使用2个Google地图点(经度和纬度)从mongodb Query中查找平方面积数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 09:41