首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Geofire / FireBase .indexOn

Geofire / FireBase .indexOn
EN

Stack Overflow用户
提问于 2015-12-10 07:02:30
回答 1查看 1.4K关注 0票数 1

我正在尝试从iOS应用程序中使用Geofire。但是我在规则定义上失败了。

这是我的数据集的样子:

代码语言:javascript
复制
offers:{ 
   user1:{
     name : "Steph",
     position : { 
         g:"xxxx",
         l: {
              0: 48.8795522,
              1: 2.3568256
         }
     }
  },
  user2:{
    name:"John",
    position:{ 
       g:"yyyy",
       l: {
          0: 48.8795528,
          1: 2.3568256
       }
    }
  }
}

在我的Swift Code中,我使用了以下内容:

代码语言:javascript
复制
let geoRef = Firebase(url: appDelegate.fireBaseUrl + "/offers"  )
let geoFire = GeoFire(firebaseRef: geoRef)
let center = CLLocation(latitude: 48.8795528, longitude:2.3568256)
let myQuery = geoFire.queryAtLocation(center, withRadius: 0.6)

我把观察者设置成这样:

代码语言:javascript
复制
_ = myQuery.observeEventType(GFEventTypeKeyEntered, withBlock: { (key: String!, position: CLLocation!) in
      print("Key '\(key)' entered")
    })
_ = myQuery.observeEventType(GFEventTypeKeyMoved, withBlock: { (key: String!, position: CLLocation!) in
      print("Key '\(key)' moved")
    })
_ = myQuery.observeEventType(GFEventTypeKeyExited, withBlock: { (key: String!, position: CLLocation!) in
      print("Key '\(key)' exited")
    })

我使用GeoFire方法为用户设置位置,如下所示:

代码语言:javascript
复制
geoFire.setLocation(CLLocation(latitude: myAdresse.Latitude, longitude: myAdresse.Longitude), forKey: "position")

但我得到了这样的信息

使用未指定索引的Firebase。考虑在您的安全规则中添加".indexOn":"g“at /offers以获得更好的性能

我尝试了几种规则的组合。

代码语言:javascript
复制
{
  "rules": {
  "offers":{
    ".read": true,
    ".write": true,
    "$users": {
        "position":{
        ".indexOn":"g"
        }
     }
   }
 }
}

我必须检查我的架构吗?还是我错过了什么?有什么帮助吗?

EN

回答 1

Stack Overflow用户

发布于 2015-12-10 08:09:31

我认为你在寻找:

代码语言:javascript
复制
{
  "rules": {
  "offers":{
    ".read": true,
    ".write": true,
    "$users": {
      ".indexOn":"position/g"
     }
   }
 }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34190678

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档