新聞中心
Command.geoNear(options: Object): Command
支持端:小程序 , 云函數(shù) , Web
10年積累的網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有馬尾免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
按從近到遠(yuǎn)的順序,找出字段值在給定點(diǎn)的附近的記錄。
參數(shù)
options: Object
| 屬性 | 類型 | 默認(rèn)值 | 必填 | 說明 |
|---|---|---|---|---|
| geometry | GeoPoint | 是 | 地理位置點(diǎn) (Point) | |
| maxDistance | number | 否 | 選填,最大距離,單位為米 | |
| minDistance | number | 否 | 選填,最小距離,單位為米 |
返回值
Command
索引要求
需對查詢字段建立地理位置索引
示例代碼
找出離給定位置 1 公里到 5 公里范圍內(nèi)的記錄
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
支持端:小程序 , 云函數(shù) , Web
找出字段值在指定區(qū)域內(nèi)的記錄,無排序。指定的區(qū)域必須是多邊形(Polygon)或多邊形集合(MultiPolygon)。
參數(shù)
options: Object
| 屬性 | 類型 | 默認(rèn)值 | 必填 | 說明 |
|---|---|---|---|---|
| geometry | Object | 是 | 地理信息結(jié)構(gòu),Polygon,MultiPolygon,或 { centerSphere } |
返回值
Command
索引要求
需對查詢字段建立地理位置索引
示例代碼 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:給定圓形
可以不用 geometry 而用 centerSphere 構(gòu)建一個圓形。
centerShpere 從公共庫 2.8.3 開始支持
centerSphere 對應(yīng)的值的定義是:[ [經(jīng)度, 緯度], 半徑 ]
半徑需以弧度計(jì),比如需要 10km 的半徑,則用距離除以地球半徑 6378.1km 得出的數(shù)字。
const _ = db.command
db.collection('restaurants').where({
location: _.geoWithin({
centerSphere: [
[-88, 30],
10 / 6378.1,
]
})
})Command.geoIntersects(options: Object): Command
支持端:小程序 , 云函數(shù) , Web
找出給定的地理位置圖形相交的記錄
參數(shù)
options: Object
| 屬性 | 類型 | 默認(rèn)值 | 必填 | 說明 |
|---|---|---|---|---|
| geometry | Object | 是 | 地理信息結(jié)構(gòu),Point |
返回值
Command
索引要求
需對查詢字段建立地理位置索引
示例代碼:找出和一個多邊形相交的記錄
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)
])
]),
})
}) 當(dāng)前名稱:創(chuàng)新互聯(lián)小程序教程:SDK數(shù)據(jù)庫Command·查詢·地理位置操作符
文章路徑:http://www.5511xx.com/article/coccpee.html


咨詢
建站咨詢

