# SDK数据库 Command·查询·地理位置操作符

2020-07-27 14:30 更新

# Command.geoNear(options: Object): Command

## 参数

### options: Object

geometry GeoPoint 地理位置点 (Point)
maxDistance number 选填，最大距离，单位为米
minDistance number 选填，最小距离，单位为米

## 示例代码

``````const _ = db.command
db.collection('restaurants').where({
location: _.geoNear({
geometry: db.Geo.Point(113.323809, 23.097732),
minDistance: 1000,
maxDistance: 5000,
})
}).get()``````

# Command.geoWithin(options: Object): Command

## 参数

### options: Object

geometry Object 地理信息结构，Polygon，MultiPolygon，或 { centerSphere }

## 示例代码 1：给定多边形

``````const _ = db.command
const { Point, LineString, Polygon } = db.Geo
db.collection('restaurants').where({
location: _.geoWithin({
geometry: Polygon([
LineString([
Point(0, 0),
Point(3, 2),
Point(2, 3),
Point(0, 0)
])
]),
})
})
``````

## 示例代码 2：给定圆形

centerShpere 从公共库 2.8.3 开始支持

centerSphere 对应的值的定义是：[ [经度, 纬度], 半径 ]

``````const _ = db.command
db.collection('restaurants').where({
location: _.geoWithin({
centerSphere: [
[-88, 30],
10 / 6378.1,
]
})
})``````

# Command.geoIntersects(options: Object): Command

## 参数

### options: Object

geometryObject地理信息结构，Point

## 示例代码：找出和一个多边形相交的记录

``````const _ = db.command
const { Point, LineString, Polygon } = db.Geo
db.collection('restaurants').where({
location: _.geoIntersects({
geometry: Polygon([
LineString([
Point(0, 0),
Point(3, 2),
Point(2, 3),
Point(0, 0)
])
]),
})
})``````

App下载