async queryRestaurentsByPolygon() {
try {
const area = new db.Geo.Polygon(
[
new db.Geo.LineString([
new db.Geo.Point(112.82216727560444, 28.134772708582847),
new db.Geo.Point(113.00070445485858, 28.134772708582847),
new db.Geo.Point(113.00070445485858, 28.46126612494616),
new db.Geo.Point(112.82216727560444, 28.46126612494616),
new db.Geo.Point(112.82216727560444, 28.134772708582847),
])
]
)
console.log(JSON.stringify(area))
const res = await db.collection('restaurants_baseinfo').where({
location: db.command.geoWithin({
geometry: area
})
}).get()
console.log(res)
return {
code: 0,
msg: '获取成功',
data: res.data,
}
} catch (error) {
//TODO handle the exception
console.log(error)
return {
errCode: 'DATABASE_ERROR',
errMsg: '数据库操作失败',
}
}
}
修改为
const area = new db.Geo.Polygon([
[
new db.Geo.Point(112.82216727560444, 28.134772708582847),
new db.Geo.Point(113.00070445485858, 28.134772708582847),
new db.Geo.Point(113.00070445485858, 28.46126612494616),
new db.Geo.Point(112.82216727560444, 28.46126612494616),
new db.Geo.Point(112.82216727560444, 28.134772708582847),
],
])
后报错信息为Error: ==右侧值类型不正确