Skip to content

Can't get near Users by my location #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mark-baumann opened this issue Feb 10, 2021 · 0 comments
Open

Can't get near Users by my location #143

mark-baumann opened this issue Feb 10, 2021 · 0 comments

Comments

@mark-baumann
Copy link

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.

 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

The App is crashing because of empty NSArray.

Thank you in advance
Mark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant