On this page本页内容
$centerSphere
Defines a circle for a geospatial query that uses spherical geometry. 为使用球形几何图形的地理空间查询定义圆。The query returns documents that are within the bounds of the circle. 该查询返回位于圆边界内的文档。You can use the 您可以在GeoJSON对象和传统坐标对上使用$centerSphere
operator on both GeoJSON objects and legacy coordinate pairs.$centerSphere
运算符。
To use 要使用$centerSphere
, specify an array that contains:$centerSphere
,请指定包含以下内容的数组:
{ <location field>: { $geoWithin: { $centerSphere: [ [ <x>, <y> ], <radius> ] } } }
Applications can use 应用程序可以使用$centerSphere
without having a geospatial index. $centerSphere
而无需地理空间索引。However, geospatial indexes support much faster queries than the unindexed equivalents.但是,地理空间索引支持的查询速度比未编制索引的等效查询快得多。
Both 2dsphere and 2d geospatial indexes support $centerSphere
.2dsphere
和2d
地理空间索引都支持$centerSphere
。
The following example queries grid coordinates and returns all documents within a 10 mile radius of longitude 以下示例查询网格坐标并返回经度88 W
and latitude 30 N
. 88 W
和纬度30 N
的10英里半径内的所有文档。The query converts the distance to radians by dividing by the approximate equatorial radius of the earth, 3963.2 miles:该查询通过除以地球的近似赤道半径3963.2英里,将距离转换为弧度:
db.places.find( { loc: { $geoWithin: { $centerSphere: [ [ -88, 30 ], 10/3963.2 ] } } } )