2011-02-09 41 views
0

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

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

我geeting反馈用于从所述位置管理器的位置:

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

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

的LocationManager:< 36.45307493, 28.22220462> +/-100.00米(速度-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); 

} 

能否请您解释一下为什么我不能访问它?

非常感谢!

回答

3

您不保留位置。这样做:

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

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