我有一个PFQueryTableView,它应该收集10个最近的商店位置并按照接近的顺序显示它们。我像这样查询tableview:
- (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:@"TopToday"];
query.limit = 7;
CLLocation *currentLocation = locationManager.location;
PFGeoPoint *userLocation =
[PFGeoPoint geoPointWithLatitude:currentLocation.coordinate.latitude
longitude:currentLocation.coordinate.longitude];
return query;
}
上面的代码工作正常,只是按顺序收集了7个随机位置。但是,当我添加这一行时:
[query whereKey:@"location" nearGeoPoint:userLocation withinMiles:50];
它只返回一个空白的默认tableview。有没有人有任何想法我为什么查询不适用于位置线?
答案 0 :(得分:0)
我的猜测是,您的位置管理器返回有效位置之前正在运行查询。
我会为当前的geopoint创建一个新属性;
@property (nonatomic, strong) PFGeoPoint *currentGeoPoint;
然后重写loadObjects以确保在查询运行之前实际存在地理点。
- (void)loadObjects
{
if (!self.currentGeoPoint)
{
[PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geo, NSError *error)
{
self.currentGeoPoint = geo;
[super loadObjects];
}];
}
else
{
[super loadObjects];
}
}
最后在查询中引用currentGepoint。
- (PFQuery *)queryForTable
{
PFQuery *query = [PFQuery queryWithClassName:@"TopToday"];
query.limit = 7;
[query whereKey:@"location" nearGeoPoint:self.currentGeoPoint withinMiles:50];
return query;
}