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.