gpt4 book ai didi

ios - Geofire/火力基地.indexOn

转载 作者:行者123 更新时间:2023-11-28 06:54:00 26 4
gpt4 key购买 nike

我想弄清楚如何从 iOS 应用程序使用 Geofire。但是我在规则定义方面失败了。

这就是我的数据集的样子:

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 代码中,我使用这个:

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] 使用未指定的索引。考虑在/offers 添加 ".indexOn": "g"到您的安全规则以获得更好的性能

我尝试了几种规则组合..

{
"rules": {
"offers":{
".read": true,
".write": true,
"$users": {
"position":{
".indexOn":"g"
}
}
}
}
}

我必须检查我的架构吗?还是我想念什么?有什么帮助吗?

最佳答案

我认为您正在寻找:

{
"rules": {
"offers":{
".read": true,
".write": true,
"$users": {
".indexOn":"position/g"
}
}
}
}

关于ios - Geofire/火力基地.indexOn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34190678/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com