我像这样通过 JSON 获取值:
{
id = 1;
latitude = "-23.0002";
longitude = "-43.2438";
name = Vips;
}
{
id = 2;
latitude = "-22.9283";
longitude = "-43.1746";
name = Elegance;
}
...
我需要在表格视图中显示这些值,按到用户位置的距离排序。并且必须始终更新此值。我怎样才能做到这一点?
displayObject 是一个 NSMutableArray,我从 WS 获取值。在 viewWillappear 我正在尝试做:
NSArray *rawData = [NSArray arrayWithArray:displayObject];
rawData = [rawData sortedArrayUsingComparator: ^(id a, id b) {
CLLocationDistance dist_a= [[a objectForKey:@"coordinate"] distanceFromLocation: locAtual];
CLLocationDistance dist_b= [[b objectForKey:@"coordinate"] distanceFromLocation: locAtual];
if ( dist_a < dist_b ) {
return (NSComparisonResult)NSOrderedDescending;
} else if ( dist_a > dist_b) {
return (NSComparisonResult)NSOrderedDescending;
} else {
return (NSComparisonResult)NSOrderedSame;
}
}];
但它不起作用。我只有,纬度和经度。我没有“坐标”。有人??
谢谢你!!