CLLocation生成奇怪的错误
问题描述:
我有一个CLLocation的问题。
我想知道两个坐标之间的距离旁边的位置在的tableView标题表现出来:CLLocation生成奇怪的错误
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
// The first CLLocation based on the coordinates my MKMapView gives me.
CLLocation *userLocation = [[CLLocation alloc] initWithLatitude:mapView.userLocation.coordinate.latitude longitude:mapView.userLocation.coordinate.longitude];
// The second CLLocation based on the coordinates which are saved as a NSNumber in my own object
CLLocation *locationForIndex = [[CLLocation alloc] initWithLatitude:[[[locations objectAtIndex:indexPath.row] latitude] doubleValue] longitude:[[[locations objectAtIndex:indexPath.row] longitude] doubleValue]];
CLLocationDistance distance = [userLocation distanceFromLocation:locationForIndex];
cell.textLabel.text = [[locations objectAtIndex:indexPath.row] title];
cell.detailTextLabel.text = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%d", distance]];
return cell;
现在我得到的错误是:
有谁有可能的解决方案?
谢谢!
答
您是否包含Core Location以及MapKit?
非常感谢!这是缺少的部分! – 2010-10-19 09:40:49
是的,我自己过去做过。你会认为MapKit会包含核心位置,但它不会...... – 2010-10-19 09:48:38