1

我已经编写了 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')
  })

这很好用: 在此处输入图像描述

我使用 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

4

0 回答 0