0

I'm using the following Firebase Geofire method to set a user's location and save it to the database. The problem is that the location is written to the root of the database (database root/userID/location). Is there a way to change it so that it saves the location to root/users/userID/location?

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

When I try to change forKey to "/users/\(userID)" I get an error stating that the key cannot contain special characters.

Thanks!

winston
  • 3,000
  • 11
  • 44
  • 75
  • Where are you setting the reference for `geoFire`? please show that code – 3stud1ant3 Sep 24 '17 at 03:14
  • 1
    GeoFire manages the entire node that you initialize it on. While it doesn't have to be the root of the database (`let geoFire = GeoFire(firebaseRef: FIRDatabase.database().reference("geo"))`), it is not possible to add additional data to the nodes. See my comment [here](https://stackoverflow.com/q/46385668), [this answer](https://stackoverflow.com/q/26184918), or [this answer](https://stackoverflow.com/a/38341118/209103) – Frank van Puffelen Sep 24 '17 at 05:32
  • @FrankvanPuffelen thanks for the reply! That did the trick. I initialized on a different node like you suggested. Also, thanks for the other links. They helped explain why Geofire enforces locations to be set on a different node. – winston Sep 24 '17 at 16:52

0 Answers0