Sono abbastanza nuovo per lavorare con Firebase e la sua libreria di ubicazioni, GeoFire. Attualmente sto affrontando qualche problema durante la strutturazione dei miei dati.Query GeoFire sulla posizione dell'utente
Al momento il mio db è qualcosa di simile a questo:.
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
Vorrei interrogare sugli utenti che si trovano vicino alla mia dell'utente attualmente collegato Per farlo non riesco a capire quale strada devo specificare.
Al momento sto facendo in questo modo (ma non funziona):
risparmio posizione attuale
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!")
}
}
recupero di altri utenti nelle vicinanze
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()
})
UPDATE
risparmio posizione attuale
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!")
}
}
recupero di altri utenti vicino
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()
})
Grazie! Ci sto provando in questo momento, ma ancora non funziona. Ho cercato in questo modo (considerando la vostra struttura db): lasciare geoFire = GeoFire (firebaseRef: root.childByAppendingPath ("user_locations")) interrogazione let = geoFire.queryAtLocation (CurrentLocation, withRadius: 10) query.observeEventType (GFEventTypeKeyEntered, withBlock: { (chiave: stringa !, posizione: CLLocation!) in stampa ("+ + + + Tasto '\ (chiave)' è entrato nell'area di ricerca ed è in posizione '\ (posizione)'") }) – giacavicchioli
Risolto, si è verificato un problema durante l'impostazione del centro query. Grazie. – giacavicchioli
Fireofase geofire-js: come ottenere l'elenco delle chiavi di vicino da posizioni statiche (fisse): http://stackoverflow.com/questions/43632746/firebase-geofire-js-how-to-get-list-of-keys -di-vicino-by-staticfixed-locations –