解析最接近点的GeoQueries

时间:2015-07-08 16:38:09

标签: ios parse-platform geopoints

我的应用可让用户看到附近的人。我正在尝试使用GeoQueries查询最接近最近的用户,应用程序获取用户当前位置并搜索存储的解析列“位置”,但我收到一条错误消息“无法调用'whereKey''类型'(字符串,nearGeoPoint:Void)'

的参数列表

任何人都知道如何解决这个问题?

 // Configure the PFQueryTableView
            self.parseClassName = "User"
            self.textKey = "fullName"
            self.pullToRefreshEnabled = true
            self.paginationEnabled = false
            
            
            
        }
        
        // Define the query that will provide the data for the table view
        override func queryForTable() -> PFQuery{
            let userGeoPoint = PFGeoPoint.geoPointForCurrentLocationInBackground {
                (geoPoint: PFGeoPoint?, error: NSError?) -> Void in
            }
            var query = PFQuery(className: "User")
            query.whereKey("location", nearGeoPoint:userGeoPoint)
          
            return query
        }
        
        //override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
        override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell {
            
            var cell = tableView.dequeueReusableCellWithIdentifier("CustomCell") as! CustomCell!
            if cell == nil {
                cell = CustomCell(style: UITableViewCellStyle.Default, reuseIdentifier: "CustomCell")
            }
            
            // Extract values from the PFObject to display in the table cell
            if let name = object?["fullName"] as? String {
                cell.name.text = name
            }
            if let type = object?["lookingFor"] as? String {
                cell.type.text = type
            }
            if let location = object?["location"] as? String {
                cell.location.text = location
            }
            
            let cover = object?["cover"] as! PFFile
            cover.getDataInBackgroundWithBlock {
                (imageData: NSData?, error: NSError?) -> Void in
                if error == nil {
                    if let imageData = imageData {
                        let image = UIImage(data:imageData)
                    }
                }
            }
            
            let profile_pic = object?["profile_pic"] as! PFFile
            profile_pic.getDataInBackgroundWithBlock {
                (imageData: NSData?, error: NSError?) -> Void in
                if error == nil {
                    if let imageData = imageData {
                        let image = UIImage(data:imageData)
                    }
                }
            }
            return cell
        }
    }

1 个答案:

答案 0 :(得分:0)

让userGeoPoint不是用户地址点,因为您试图暗示您的代码。 geoPointForCurrentLocationInBackground函数返回void,因此您尝试分配一个类型为void的类型为PFGeoPoint的类型。由于该函数是异步的,因此您必须等待回调以确定您是否已成功接收PFGeoPoint。

PFGeoPoint.geoPointForCurrentLocationInBackground {
            (geoPoint: PFGeoPoint?, error: NSError?) -> Void in
            if(error == nil){
                  //query ran successfully, extract the geopoint and do whatever
            }
            else{
                  //Error
            }
        }