2011-02-09 2 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.00m (скорость -1.00 ОББ/курс -1.00) @ 9/2/11 10:14:58 π.μ. GMT + 02: 00

, но когда я пытаюсь получить доступ к CurrentLocation из DidSelectAnnotationView я получаю 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); 
    } 
} 
Смежные вопросы