1

テーブル ビューに mysql データベースの名前が入力されています。ユーザーの場所に最も近い距離でテーブルをフィルター処理したいと考えています。取得するデータには、距離として使用したい座標値があります。

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;
}
4

0 に答える 0