$centerSphere

在本页面

Definition

要使用$centerSphere,请指定一个包含以下内容的数组:

{
   <location field>: {
      $geoWithin: { $centerSphere: [ [ <x>, <y> ], <radius> ] }
   }
}

Important

如果您使用经度和纬度,请指定 longitude first

Behavior

应用程序可以使用$centerSphere *不具有地理空间索引。但是,地理空间索引比未索引的等效索引支持更快的查询。

2dsphere2d地理空间索引均支持$centerSphere

Example

以下示例查询网格坐标,并返回经度88 W和纬度30 N的 10 英里半径内的所有文档。该查询通过除以大约 3963.2 英里的地球赤道半径来将距离转换为弧度:

db.places.find( {
  loc: { $geoWithin: { $centerSphere: [ [ -88, 30 ], 10/3963.2 ] } }
} )
首页