当前位置: 首页 > 面试题库 >

用户位置上的GeoFire查询

卞坚成
2023-03-14
问题内容

我对使用Firebase及其位置库GeoFire感到很陌生。目前,我在构造数据时遇到一些问题。

目前,我的数据库是这样的:

users
  facebook:xxxxx
    displayName: xx
    firstName: xx
    lastName: xx
    location:
      g: xxxx
      l:
        0: xxx
        1: xxx
  facebook:yyyyy
    displayName: yy
    firstName: yy
    lastName: yy
    location:
      g: yyyy
      l:
        0: yyy
        1: yyy

我想查询当前登录用户附近的用户。为此,我无法理解必须指定的路径。

目前,我正在这样做(但这不起作用):

保存当前位置

let root = Firebase(url: "myapp.firebaseio.com")
let usersRoot = root.childByAppendingPath("users")
geoFire = GeoFire(firebaseRef: usersRoot.childByAppendingPath(root.authData.uid))

geoFire.setLocation(currentLocation, forKey: "location") { (error) in
   if (error != nil) {
      print("An error occured: \(error)")
   } else {
      print("Saved location successfully!")
   }
}

检索附近的其他用户

let geoFire = GeoFire(firebaseRef: Firebase(url: "myapp.firebaseio.com").childByAppendingPath("users"))
let query = geoFire.queryAtLocation(currentLocation, withRadius: radius)

query.observeEventType(GFEventTypeKeyEntered, withBlock: {
   (key: String!, location: CLLocation!) in

   print("+ + + + Key '\(key)' entered the search area and is at location '\(location)'")
   self.userCount++
   self.refreshUI()
})

更新

保存当前位置

let root = Firebase(url: "myapp.firebaseio.com")
geoFire = GeoFire(firebaseRef: root.childByAppendingPath("locations"))

geoFire.setLocation(currentLocation, forKey: root.authData.uid) { (error) in
   if (error != nil) {
      print("An error occured: \(error)")
   } else {
      print("Saved location successfully!")
   }
}

检索附近的其他用户

let geoFire = GeoFire(firebaseRef: Firebase(url: "myapp.firebaseio.com").childByAppendingPath("locations"))
let query = geoFire.queryAtLocation(currentLocation, withRadius: radius)

query.observeEventType(GFEventTypeKeyEntered, withBlock: {
   (key: String!, location: CLLocation!) in

   print("+ + + + Key '\(key)' entered the search area and is at location '\(location)'")
   self.userCount++
   self.refreshUI()
})

问题答案:

对于GeoFire,您必须在仅包含地理位置的树中保留一个分段,然后在树中保留另一个包含有关项目的其他信息的分段。

user_locations
  uid1:
    g: xxxx
    l:
      0: xxx
      1: xxx
  uid2:
    g: xxxx
    l:
      0: xxx
      1: xxx
user_profiles:
  uid1:
    name: "giacavicchioli"
  uid2:
    name: "Frank van Puffelen"


 类似资料:
  • 我的问题是,有人知道如何将用户的位置添加到地图上吗?我对这项技术是新的,我不太了解它。 如果您需要任何更多的代码或inormation,让我知道。

  • 所以我有一个问题,我对android编程很陌生,我开始编程android应用程序才6-8周,所以我可能是盲人,看不到简单的答案,但我的问题是: 我正在做一个学校项目,我试图开发一个类似于今天日历分割视图中的日历(下面的一个) 我用GridLayoutManager创建了一个RecyclerView,如下所示: 在此之前,一切都很好,但我正在尝试实现一个按钮,该按钮将日历设置为今天的日期,问题是当我

  • 这是我的代码,我将标记添加到半径内的位置 我想数一数半径内的标记

  • 问题内容: 我有一个很大的swing应用程序,我想让它记住所有窗口,jframe等的大小。因此,如果用户按自己的喜好调整窗口大小,则下次窗口看起来完全一样。 我是否有更好的解决方案,但是可以在“首选项”中手动编写每个窗口的位置/大小?有什么方便的方法可以在JTable中存储列的顺序吗?可能是一些框架?只是不想写样板。 不幸的是,整个大型应用程序的序列化不是一种选择。 问题答案: 不,没有。不要忘了

  • 问题内容: 我有一个要求,我必须在其中找到用户的地理位置。我使用了将用户的地址存储在数据库中然后显示该用户的地理位置的代码,现在假设用户将其位置更改为其他位置。如果用户现在从该地区或国家登录,如何我应该显示该用户的Geoip。我使用的代码是: 有没有其他选择,我可以找到用户的确切位置。请帮助 问题答案: Node-GeoIP可能是一种解决方案,但请记住,基于ip的地理定位并不总是真实的。

  • 我正在使用Microsoft Graph API,我试图实现的是将我办公室位置的所有人从Azure AD导入到我的个人联系人中。 使用图形资源管理器,我可以在中使用-所以使用。见以下结果: 因此,该用户(我)有一个属性,我希望对该属性进行筛选,以便让我的所有同事都在同一办公室。因此,我尝试了: 这是否意味着我不允许对此属性进行筛选?那就太不幸了。如果是这样--我可以申请任何变通办法?