On this page
$centerSphere
在本页面
Definition
$centerSphere
- 为使用球形几何的geospatial查询定义一个圆。该查询返回圆范围内的文档。您可以在GeoJSON对象和旧版坐标对上使用$centerSphere运算符。
要使用$centerSphere,请指定一个包含以下内容的数组:
圆心的网格坐标,以及
圆的半径,以弧度为单位。要计算弧度,请参见使用球面几何计算距离。
{
<location field>: {
$geoWithin: { $centerSphere: [ [ <x>, <y> ], <radius> ] }
}
}
Important
如果您使用经度和纬度,请指定 longitude first 。
Behavior
应用程序可以使用$centerSphere *不具有地理空间索引。但是,地理空间索引比未索引的等效索引支持更快的查询。
2dsphere和2d地理空间索引均支持$centerSphere。
Example
以下示例查询网格坐标,并返回经度88 W
和纬度30 N
的 10 英里半径内的所有文档。该查询通过除以大约 3963.2 英里的地球赤道半径来将距离转换为弧度:
db.places.find( {
loc: { $geoWithin: { $centerSphere: [ [ -88, 30 ], 10/3963.2 ] } }
} )