Skip to content

Can't get near Users by my location #143

@mark-baumann

Description

@mark-baumann

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions