firebase / firebase/geofire-objc

Can't get near Users by my location

Open
#143 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Objective-C
Stars
447
Forks
183
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.