views:

33

answers:

1

Hi,
I have got a problem with a CLLocation.
I wanted to know the distance between two coordinates to show it next to the title of the location in a tableView:

    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;

Now the error I get is:

"_OBJC_CLASS_$_CLLocation", referenced from:

Does anyone has a possible solution?

Thanks!!

+1  A: 

Have you included the Core Location framework along with MapKit?

Robert Redmond
Thanks a lot!!! That's the missing part!!
Lars Petersen
Yeah done that myself in the past. You'd think MapKit would include Core Location but it doesn't...
Robert Redmond