2017-02-03 8 views
0

Я использую geofire для расположения saving.My кода прилагается ниже, Расположения Saving Кода:запроса для выборки близлежащего местоположения не выполняется

let usersRoot = ref.child("geograpgicalLocationDetails") 
    let geoFire = GeoFire(firebaseRef: usersRoot.child(userID!)) 

    geoFire?.setLocation(CLLocation(latitude: (self.currentLocation?.latitude)!, longitude:(self.currentLocation?.longitude)!), forKey:"location") { (error) in 
     if (error != nil) { 
      print("An error occured: \(error)") 
     } else { 
      print("Saved location successfully!") 
     } 
    } 

Nearby location fetching:    

     var allKeys = [String:CLLocation]() 

     let query = geoFire?.query(at: center, withRadius: 0.001) 
     print("about to query") 
     query?.observe(GFEventType.init(rawValue: 0)!, with: {(key: String?, location: CLLocation?) in 
      print("Key: \(key), location \(location?.coordinate.latitude)") 
      allKeys [key!] = location 
     }) 

Моим вопрос местоположение выборка запрос не выполняется, так что я не могу получить результат. Пожалуйста, помогите мне

ответ

0
let ref = FIRDatabase.database().reference() 
let geoFire = GeoFire(firebaseRef: ref.child("users_location")) 

func findNearbyUsers() { 

    if let myLocation = myLocation { 

     let theGeoFire = GeoFire(firebaseRef: ref.child("users_location")) 
     let circleQuery = theGeoFire!.query(at: myLocation, withRadius: radiusInMeters/1000) 

     _ = circleQuery!.observe(.keyEntered, with: { (key, location) in 

      if !self.nearbyUsers.contains(key!) && key! != FIRAuth.auth()!.currentUser!.uid { 
       self.nearbyUsers.append(key!) 
      } 

     }) 

     //Execute this code once GeoFire completes the query! 
     circleQuery?.observeReady({ 

      for user in self.nearbyUsers { 

       self.ref.child("users/\(user)").observe(.value, with: { snapshot in 
        let value = snapshot.value as? NSDictionary 
        print(value) 
       }) 
      } 

     }) 

    } 

} 

Попробуйте этот.

+0

не выполнять код внутри circleQuery! .observe() query –

+0

@ priya.vr его работающий штраф теперь проверьте его –