【问题标题】:How to get query firestore with geofirestore and get documents in swift如何使用 geofirestore 获取查询 firestore 并快速获取文档
【发布时间】:2020-11-09 12:56:39
【问题描述】:

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

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 对象。 我不知道如何获取查询过滤的实际文档。

【问题讨论】:

    标签: swift firebase google-cloud-firestore geofirestore


    【解决方案1】:

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

    【讨论】:

    • 我已经阅读了 geofirestore 文档,我可以解决这个问题。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-16
    • 2020-11-21
    • 2022-07-11
    • 2020-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多