0

I already got the own user Location of the User with CL Location Manager. This Location is also already in the Firebase Database at "koordinaten". Now I want to take the User Coordinate of the current User and look for Users which are in the same Area. If they are they should get a Pin on the Map of the current user.

I have therefore this code:

let db = Firestore.firestore()
db.collection("users").whereField("uid", isEqualTo: Auth.auth().currentUser?.uid ?? "x")
    .getDocuments { (querySnapshot, err) in
        
        let location = querySnapshot!.documents[0].get("koordinaten")
        
        let geofire = GeoFire(firebaseRef: querySnapshot!.documents[0].get("koordinaten") as! DatabaseReference)
        
        let center = CLLocation(coder: location as! NSCoder)
        
        let circleQuery = geofire.query(at: center!, withRadius: 5000000000000000000000000000);
        
        
        var queryHandle = circleQuery.observe(.keyEntered) { (key: String!, location: CLLocation!) in
            
            print("Key '\(String(describing: key))' entered the search area and is at location '\(String(describing: location))'")
            
            let newPin = MKPointAnnotation()
            newPin.coordinate = location.coordinate
            self.MapView.addAnnotation(newPin)
        }
}

But it actually don't work as it should. Does anyone know how to solve this? I know there are similar questions...but the code for example from Retrieving Keys From GeoFire within Radius in Swift does not work at my App? frustrating.

Andreas Oetjen
  • 9,889
  • 1
  • 24
  • 34
  • So what is the output? Will both closures be executed? Maybe add some more print statements to find out what is called. – Andreas Oetjen Feb 05 '21 at 11:36
  • Output is output is: " " –  Feb 05 '21 at 11:53
  • Do you know what it is? –  Feb 07 '21 at 08:50
  • I don't understand what you mean with _output_? There is just one print statement, and this prints something like "Key ... entered the search area and is at location ...". Will this be outputtet, or where do you output what? – Andreas Oetjen Feb 07 '21 at 20:35
  • As i understand, the output should print the key of the other user and the location of the other user....but it only prints hex GeoFire –  Feb 08 '21 at 11:16
  • I see. So the output is not from you, i.e. `circleQuery.observe` does not seem to call the closure. Please put a breakpoint to the line `let location = ...` and to the line with the `print` statement and check if they are executed. – Andreas Oetjen Feb 08 '21 at 13:13
  • no location is not printing.... print(location!) –  Feb 10 '21 at 12:39

0 Answers0