0

Right now I have a latitude and longitude for each user, under the child(uid).child("Coordinates"). Now I want to rather(or also) store the latitude and longitude as a geohash, to be user by Geofire. Where am I going wrong?

    guard let locValue: CLLocationCoordinate2D = manager.location?.coordinate else { return }
    print("locations = \(locValue.latitude) \(locValue.longitude)")
    latestLocation = ["latitude" : locValue.latitude, "longitude" : locValue.longitude]
    let lat = locValue.latitude
    let lon = locValue.longitude
    dict = CLLocation(latitude: lat, longitude: lon)
    print("dict", dict)
    if let locationDictionary = latestLocation {
databaseRef.child("people").child(uid).child("Coordinates").setValue(locationDictionary) /////this above is for the separate entries, below I tried to also add it as a geohash.
        let geofireRef = Database.database().reference().child("people").child("CoordinatesB")
        let geoFire = GeoFire(firebaseRef: geofireRef)
        geoFire.setLocation(CLLocation(latitude: lat, longitude: lon), forKey: "firebase-hq")
    }//////
noname87f
  • 19
  • 4
  • What doesn't work about the code you shared when you run it? For example: if you step through it in a debugger line-by-line, which specific line doesn't do what you expect it to do? – Frank van Puffelen Nov 13 '20 at 15:41
  • Basically the GeoFire part doesn't work. It doesn't write anything to my realtime database. I printed (geoFire, "geo") and it didn't output anything in console. There is no geohash in my realtime db. – noname87f Nov 13 '20 at 20:12
  • Did you check if there's any error in the debug output when that line executes?? – Frank van Puffelen Nov 13 '20 at 21:25
  • Yes, no error. That lead me to believe the code simply didn't execute (because presumably I made a mistake somewhere). The only other possibility I thought of is Rules that don't allow the write. But then I should have received an error for that. – noname87f Nov 13 '20 at 23:12
  • If the write is rejected on the server, you should get a (permission denied) error. I don't see what's going wrong if that's not the cause, so hope somebody else spots it. – Frank van Puffelen Nov 14 '20 at 00:09

0 Answers0