CLLocation 获取 EXC_BAD_ACCESS

发布于 2024-10-16 23:46:08 字数 922 浏览 1 评论 0原文

我在尝试访问 CLLocation 时遇到错误,您能解释一下原因吗?

CLLocation *currentLocation;
@property (nonatomic, retain) CLLocation *currentLocation;

我从位置经理处收到有关该位置的反馈:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

    if (newLocation != nil) {
        currentLocation = newLocation;
        NSLog(@"locationManager: %@", currentLocation);
    }
}

位置经理:<+36.45307493, +28.22220462> +/- 100.00m(速度 -1.00 mps/航向 -1.00)@ 9/2/11 10:14:58 π.μ。 GMT+02:00

但是当我尝试从 DidSelectAnnotationView 访问 currentLocation 时,我得到 EXC_BAD_ACCESS:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {

    NSLog(@"current Location: %@", currentLocation);

}

您能解释一下为什么我无法访问它吗?

非常感谢!

I am getting an Error when trying to access a CLLocation, can you please explain why?

CLLocation *currentLocation;
@property (nonatomic, retain) CLLocation *currentLocation;

I am geeting feedback for the location from the location manager:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

    if (newLocation != nil) {
        currentLocation = newLocation;
        NSLog(@"locationManager: %@", currentLocation);
    }
}

locationManager: <+36.45307493,
+28.22220462> +/- 100.00m (speed -1.00 mps / course -1.00) @ 9/2/11 10:14:58
π.μ. GMT+02:00

but when I am trying to access currentLocation from DidSelectAnnotationView i get the EXC_BAD_ACCESS:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {

    NSLog(@"current Location: %@", currentLocation);

}

can you please explain why I cannot access it?

Many Thanks!

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

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

发布评论

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

评论(1

绝不放开 2024-10-23 23:46:08

您不会保留该位置。这样做:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

    if (newLocation != nil) {
        self.currentLocation = newLocation; /// The change is here
        NSLog(@"locationManager: %@", currentLocation);
    }
}

You are not retaining the location. Do it like:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

    if (newLocation != nil) {
        self.currentLocation = newLocation; /// The change is here
        NSLog(@"locationManager: %@", currentLocation);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文