GeoFireStore 查询始终返回 {}

问题描述

我编写了 2 个 Firebase 函数

1、让用户签到一个位置

2、查询附近位置

签到代码是:

.https.onRequest(async(request,response) =>{
     const uid = request.query.uid
     const cat = request.query.cat
     const addr = request.query.add
     const name = request.query.name
     const long = Number(request.query.long)
     const lat = Number(request.query.lat)
     const gpoint = new admin.firestore.GeoPoint(lat,long)
     const db = admin.firestore()
     const tstamp = Date.Now()
     const adata = {
        createdate: tstamp,checkins: 1,lastcheckin: tstamp,status: null,createdby: uid,category: cat,address: addr,name: name,lat: lat,long: long,gid: null,g: {
          coordinates: gpoint,},}
      await db.collection('places').add(adata)
      response.send('OK')
  })

效果很好:

enter image description here

我使用 GPS 坐标查找附近地点的查询功能是:

.https.onRequest(async(request,response) =>{
     const long= Number(request.query.long)
     const lat = Number(request.query.lat)
     const GeoFirestore = require('geofirestore').GeoFirestore
     const database = admin.firestore();
    const geofirestore = new GeoFirestore(database);
    const Geo = geofirestore.collection('places')
    const query = Geo.near({center: new admin.firestore.GeoPoint(lat,long),radius: 10 })
     query.get()
      .then((snapshot: { data: () => any }) =>{
       // const data =(snapshot.data())
        response.send(snapshot.data())
     })
       .catch((error: any) => {
           console.log(error)
           response.status(500).send(error)
       })
        })

当我在浏览器中运行查询时.../getplaces?long=46.93351240000001&lat=13.1321528

它总是返回 {}

我哪里出错了?

TIA

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)