I wrote following code in the location Manager didUpdateLocation function.
First I grabbed my own location as a CCLocationCoridnate2D.
if let location = locations.last{ let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
Than I made a query to get all users near by my location.
let geofireRef = Database.database().reference()
let geoFire = GeoFire(firebaseRef: geofireRef)
geoFire.setLocation(CLLocation(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude), forKey: "test")
let centerQuery = CLLocation(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
let circleQuery = geoFire.query(at: centerQuery, withRadius: 5)
var queryHandle = circleQuery.observe(.keyEntered, with: { (key: String!, location: CLLocation!) in
print("Key '\(key)' entered the search area and is at location '\(location)'")
})
If I now want to replace "test" with my actual user (userdocid) it won't work.
How I grab my User:
Firestore.firestore().collection("users").whereField("uid", isEqualTo: Auth.auth().currentUser?.uid ?? "x")
.getDocuments { (querySnapshot, err) in
if err != nil {
print("Failed")
return
}
let userdocid = querySnapshot!.documents[0].documentID
Hello ,
I want to get all Users near by my own Location.
I wrote following code in the location Manager didUpdateLocation function.
First I grabbed my own location as a CCLocationCoridnate2D.
if let location = locations.last{ let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
Than I made a query to get all users near by my location.
If I now want to replace "test" with my actual user (userdocid) it won't work.
How I grab my User:
The App is crashing because of empty NSArray.
Thank you in advance Mark