Uitableview 按距用户位置的距离筛选表视图

Uitableview 按距用户位置的距离筛选表视图,uitableview,cllocationmanager,cllocationcoordinate2d,Uitableview,Cllocationmanager,Cllocationcoordinate2d,我有一个使用mysql数据库中的名称填充的表视图,我想通过与用户位置最近的距离来过滤表。Im检索的数据具有我要用作距离的坐标值 Route * routeObject; //data from mysql CGFloat latitude = [routeObject.startLat doubleValue]; CGFloat longitude = [routeObject.startLong doubleValue]; CLLocationCoordinate2D startCoord

我有一个使用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;
}

基本上,您必须对数据源进行排序(在您的例子中是routesArray),然后调用reloadData。这里有一种按距离对数组排序的方法:您还需要支持吗?@user3071962是的,目前正在尝试处理前面的注释。