May 20, 2021 WeChat Mini Program Development Document
Support: small programs, cloud functions, web
Find records of field values near a given point in order from near to far.
Property | Type | The default | Required | Description |
---|---|---|---|---|
geometry | GeoPoint | Is | Location Point | |
maxDistance | number | Whether | Optional fill, maximum distance, in meters | |
minDistance | number | Whether | Optional, minimum distance, in meters |
The query field needs to be indexed geographically
Find records within 1 km to 5 km of a given location
const _ = db.command
db.collection('restaurants').where({
location: _.geoNear({
geometry: db.Geo.Point(113.323809, 23.097732),
minDistance: 1000,
maxDistance: 5000,
})
}).get()
Support: small programs, cloud functions, web
Find records with field values in the specified area, no sorting. The specified area must be Polygon or Polygon.
Property | Type | The default | Required | Description |
---|---|---|---|---|
geometry | Object | Is | Geo-information structure, Polygon, MultiPolygon, or s centerSphere |
The query field needs to be indexed geographically
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)
])
]),
})
})
You can build a circle with centerSphere instead of geometry.
CenterShpere starts with public library 2.8.3
The corresponding value of centerSphere is defined as: .
The radius needs to be measured in radian, e.g. a radius of 10km, divided by the distance by the earth radius of 6378.1km.
const _ = db.command
db.collection('restaurants').where({
location: _.geoWithin({
centerSphere: [
[-88, 30],
10 / 6378.1,
]
})
})
Support: small programs, cloud functions, web
Find records where a given geographic graph intersects
Property | Type | The default | Required | Description |
---|---|---|---|---|
geometry | Object | Is | Geographic information structure, Point |
The query field needs to be indexed geographically
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)
])
]),
})
})