2016-07-29 2 views
1

現在のユーザーのPFGeopointから特定の距離内にいるすべてのユーザーを検索しようとしています。withinMileはSwiftでPFGeopointのParseクエリを処理しません

クエリ.whereKey( "addressPoint"、nearGeoPoint:userGeopoint)!使用している場合、クエリオブジェクトを返します

をしかし使用した場合、それにはオブジェクトを返しません:

クエリ.whereKey( "addressPoint"、nearGeoPointを! :userGeopoint、withinMiles:100)

クパチーノのシミュレータの位置から100マイル以内に約20人のユーザーがいるので、問題はありません。ここ

は完全なコードである:のviewDidLoad FUNC

オーバーライド(){

super.viewDidLoad() 

VAR userGeopoint = PFGeoPoint()

PFGeoPoint.geoPointForCurrentLocationInBackground { 
     (geoPoint: PFGeoPoint?, error: NSError?) -> Void in 

     if error == nil { 
      userGeopoint = geoPoint! 
      //print(userGeopoint) 
     } 
    } 

    let query = PFUser.query() 
    query!.whereKey("addressPoint", nearGeoPoint: userGeopoint, withinMiles: 1000) 
    query!.limit = 20 
    query!.orderByDescending("updatedAt") 
    query?.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in 

     if error == nil { 

     if let users = objects { 
     for object in users { 
       if let user = object as? PFUser { 
        if user != PFUser.currentUser() { 
         print(user["addressPoint"]) 
         } 
        } 
      } 

} }他{ プリント(エラー) } }) }

答えて

0

これは数秒かかる可能性があります。そのため、PFGeoPoint.geoPointForCurrentLocationInBackgroundはメインスレッドで実行されていません。その中にクエリを入れてください...また、私はそのクエリを距離は100マイルに限定されます

PFGeoPoint.geoPointForCurrentLocationInBackground { 
    (geoPoint: PFGeoPoint?, error: NSError?) -> Void in 
    if error == nil { 
     let query = PFUser.query() 
     query!.whereKey("addressPoint", nearGeoPoint: geoPoint, withinMiles: 100) 
     //... rest of the query 
    } 
} 
関連する問題