新手小白,自己搞了几天了,还是不行,求指点、求帮助。
async onLoad(options) {
// 查询一个集合中所有记录
const db = wx.cloud.database()
let count = await db.collection('menDian').count()
count = count.total
let all =[]
for (let i=0;i<count;i+=20){
let list = await db.collection('menDian').skip(i).get()
all = all.concat(list.data);
}
console.log(all)
// 获取用户位置
wx.getLocation({
type: 'wgs84',
success (res) {
console.log(res)
const latitude = res.latitude
const longitude = res.longitude
// 由近到远排列,这里搞不懂了
db.collection('mendian').aggregate()
.geoNear({
distanceField: 'this.menDianXinXi.item.jingweidu', // 输出的每个记录中 distance 即是与给定点的距离
spherical: true,
near: db.Geo.Point(longitude,latitude),
}).end()
.then(res =>{
console.log(res)
})
},