【问题标题】:Query specific nodes from Firebase using Geofire?使用 Geofire 从 Firebase 查询特定节点?
【发布时间】:2017-12-19 19:42:38
【问题描述】:

怎么样了?

我在 Firebase 中有以下数据结构:

  reports  
   .XbCacF7tHosOZxxO(child generated by auto-id)  
     ..userId: "XvSjDkLsaA8Se"  
     ..message: "Text goes here"  
     ..latitude: "30.123131"  
     ..longitude: "50.3313131"

   .Yoa7HsgTuWm97oP(child generated by auto-id)  
     ..userId: "XvSjDkLsaA8Se"  
     ..message: "Text goes here 2"  
     ..latitude: "30.99999"  
     ..longitude: "50.99999"  

  users  
   .XvSjDkLsaA8Se  
     ..name: "John"  
     ..email: "john@email.com" 

该应用程序的理念是用户可以制作多个“报告”。

将来,如果我有数百个“报告”,我不希望它使我的查询超载。所以我试图找到一种使用 Geofire 查询的方法。

我的问题是:有没有办法使用 Geofire 的半径功能和“报告”中的纬度和经度仅获取我附近的“报告”?

谢谢!

【问题讨论】:

    标签: swift database firebase geofire


    【解决方案1】:

    我刚刚找到了一种方法。

    我必须将我的 Geofire 节点“reports_locations”保存为在创建报告时由 Auto Id 生成的相同 ID。

    我的应用在 Firebase 上保存数据的功能:

    //Save data to Firebase Database
    let key = report.childByAutoId().key
    report.child(key).setValue(dataToSaveInFirebase)
    
    //Save data to Geofire node
    let userLocal = database.child("reports_locations")
    let geoRef = GeoFire(firebaseRef: userLocal)
    
    let location = CLLocation(latitude: self.localUser.latitude, longitude: self.localUser.longitude)
    
    geoRef?.setLocation(location, forKey: key)
    

    我希望它可以帮助其他人。

    【讨论】:

      猜你喜欢
      • 2016-07-12
      • 1970-01-01
      • 1970-01-01
      • 2014-12-12
      • 2021-10-31
      • 2016-08-16
      • 2016-09-30
      • 2017-08-09
      • 1970-01-01
      相关资源
      最近更新 更多