我有一个用mysql数据库中的名称填充的表视图,我想按离用户位置的最近距离过滤表。 Im检索的数据具有我想用作距离的坐标值。
Route * routeObject; //data from mysql
CGFloat latitude = [routeObject.startLat doubleValue];
CGFloat longitude = [routeObject.startLong doubleValue];
CLLocationCoordinate2D startCoord = CLLocationCoordinate2DMake(latitude, longitude);
我得到的用户位置如下:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
if (newLocation)
{
if ((oldLocation.coordinate.latitude != newLocation.coordinate.latitude) &&
(oldLocation.coordinate.longitude != newLocation.coordinate.longitude))
self.userCoord = [NSString stringWithFormat:@"%f,%f",newLocation.coordinate.latitude, newLocation.coordinate.longitude];
NSLog(@"%@", self.userCoord);
}
}
现在我无法过滤表格,我不知道/了解如何通过距离用户位置组织单元格的任何想法?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
Route * routeObject;
routeObject = [routesArray objectAtIndex:indexPath.row];
cell.textLabel.text = routeObject.name;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}