1
我試圖找出從iOS應用程序使用Geofire。 但我對規則定義失敗。Geofire/FireBase .indexOn
這是怎麼了,看起來我的數據集,如:
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
}
}
}
}
從我的銀行代碼,我用這個:
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)
我這樣設置的觀察員
_ = 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方法爲用戶設置位置,如下所示:
geoFire.setLocation(CLLocation(latitude: myAdresse.Latitude, longitude: myAdresse.Longitude), forKey: "position")
但我收到此消息
[Firebase]使用未指定的索引。考慮加入「.indexOn」:‘G’的/你的安全規則提供了更好的性能
我試過幾種組合的規則..
{
"rules": {
"offers":{
".read": true,
".write": true,
"$users": {
"position":{
".indexOn":"g"
}
}
}
}
}
我必須檢討我的架構?或者我錯過了什麼? 有什麼幫助嗎?
感謝,但現在看來,這不工作 – Stan92
訂購深路徑中(HTTPS [在火力地堡SDK適用於iOS 2.4版本中引入了]:// www.firebase.com/blog/2015-09-24-atomic-writes-and-more.html)。所以確保你在使用它。但我也很肯定[Geofire使用節點的優先級來存儲Geohash](https://github.com/firebase/geofire-objc/blob/master/GeoFire/Implementation/GeoFire.m#L83- L108)的值,所以你不必顯式索引它。 –