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