GeoFire-Abfrage zum Benutzerstandort

Ich bin ziemlich neu in der Arbeit mit Firebase und seiner Standortbibliothek GeoFire. Derzeit habe ich ein Problem mit der Strukturierung meiner Daten.

Im Moment ist meine db ungefähr so:

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

Ich möchte nach Benutzern fragen, die sich in der Nähe meines aktuell angemeldeten Benutzers befinden. Dazu kann ich nicht verstehen, welchen Pfad ich angeben muss.

Im Moment mache ich so (aber das funktioniert nicht):

Speichern des aktuellen Standorts

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!")
   }
}

andere Benutzer in der Nähe von @ abruf

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()
})

AKTUALISIERE

Speichern des aktuellen Standorts

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!")
   }
}

andere Benutzer in der Nähe von @ abruf

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()
})

Antworten auf die Frage(6)

Ihre Antwort auf die Frage