0

问题

我想开始使用 React 和Geofirestore。当我尝试不同的查询时,我只能从我的 Firestore 数据库中检索一个文档。

反应组件

const GeoFirestoreComp = () => {
   const firestore = firebase.firestore();
   const GeoFirestore = geofirestore.initializeApp(firestore);
   // Create a GeoCollection reference
   const geocollection = GeoFirestore.collection('restaurants');
   // Create a GeoQuery based on a location
   const query = geocollection.near({ center: new firebase.firestore.GeoPoint(56.183189, 9.551720), radius: 1000 });
   
   EXAMPLES BELOW!!! 

   return(
    <div>
    .....
    </div>
   )
}

GeoFirestore js 文档中的示例

query.get().then((value) => {
// All GeoDocument returned by GeoQuery, like the GeoDocument added above
    console.log(value.docs);
});

另一个例子 也用'geocollection'而不是'query'

    query.get().then((querySnapshot) => {
      querySnapshot.docChanges().forEach((change) => {
        console.log(change);
      });
    })

像上面的第三个例子 也用'geocollection'而不是'query'

query.limit(100).near({
    center: new firebase.firestore.GeoPoint(56.183189, 9.551720), 
    radius: 1000
}).get().then((querySnapshot) => {
    querySnapshot.docChanges().forEach((change) => {
        console.log(change.doc);
    });
});
4

0 回答 0