CLLocation 生成奇怪的错误

发布于 2024-09-28 16:48:10 字数 1353 浏览 11 评论 0 原文

我遇到了 CLLocation 问题。
我想知道两个坐标之间的距离,以将其显示在 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;

现在我得到的错误是:

有人有可能的解决方案吗?

谢谢!!

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!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

银河中√捞星星 2024-10-05 16:48:10

您是否已将 Core Location 框架与 MapKit 一起包含在内?

Have you included the Core Location framework along with MapKit?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文