使用 Firebase (GeoFire) 和 Swift 无法通过我的位置靠近用户

问题描述

我想让所有用户靠近我自己的位置。

我在位置管理器 didUpdateLocation 函数中编写了以下代码。

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)

我做了一个查询,让所有用户都靠近我的位置。

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)'")
                
                
                
            })

如果我现在想用我的实际用户 (userdocid) 替换“test”,它将不起作用。

我如何抓住我的用户:

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

应用因 NSArray 为空而崩溃。

先谢谢你 标记

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)