0

我尝试了下面的代码来获取附近某个位置过滤的位置数据。但我不知道如何获取文件。

FirebaseApp.configure()
        let db = Firestore.firestore()
        let geoFirestoreRef = db.collection("spot")
        let geoFirestore = GeoFirestore(collectionRef: geoFirestoreRef)
        
        // Query using CLLocation
        let center = CLLocation(latitude: 35.681236, longitude: 139.767125)
        // Query locations at [37.7832889, -122.4056973] with a radius of 100km
        var circleQuery = geoFirestore.query(withCenter: center, radius: 100.0)

        let _ = circleQuery.observe(.documentEntered, with: { (key, location) in
            geoFirestoreRef.document(key!).getDocument  { (document, error) in
                           if let document = document, document.exists {
                               print(document)
                           } else {
                               print("Document does not exist.")
                           }
                       }
            print("The document with documentID '\(key)' entered the search area and is at location '\(location)'")
        })
circleQuery

这个变量只返回 GFSCircleQuery 对象。我不知道如何获取通过查询过滤的实际文档。

4

1 回答 1

0

当您在 Firebase 中有查询时,您可以调用 .getDocuments 或类似的方法。Firebase 有非常详细的在线文档,您可能应该从这些文档开始。https://firebase.google.com/docs

于 2020-11-09T23:00:06.643 回答