GeoFire查询数据列表

问题描述 投票:-1回答:1

我在Firebase实时数据库中有关于这样结构的帖子的数据:

posts:
    key1:
        author: Jake
        location:
            g: xxxx
                0: yyyy
                1: yyyy
    key2:
        author: Daniel
        location:
            g: xxxx
                0: yyyy
                1: yyyy

如何使用GeoFire查询我的数据库以仅查找指定半径范围内的帖子?有没有办法更改数据库中的.indexOn规则来执行此操作?

提前致谢

ios swift firebase firebase-realtime-database geofire
1个回答
2
投票

我认为您需要将GeoFire与UserDatabase分开

设置位置呼叫

geoFire.setLocation(CLLocation(latitude: 37.7853889, longitude: -122.4056973), forKey: **UserID** )

然后创建Circle Query

let center = CLLocation(latitude: 37.7832889, longitude: -122.4056973)
var circleQuery = geoFire.queryAtLocation(center, withRadius: 0.6) // 600m

你对数据库进行调用

var queryHandle = query.observeEventType(.KeyEntered, withBlock: { (key: String!, location: CLLocation!) in
  print("Key '\(key)' entered the search area and is at location '\(location)'")
})

返回的每个Key都将是数据库的UserID,您可以通过/ User / {UserID} / ...访问相关路径。

© www.soinside.com 2019 - 2024. All rights reserved.