Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone CLLocation获取EXC\u错误\u访问_Iphone_Mkmapview - Fatal编程技术网

Iphone CLLocation获取EXC\u错误\u访问

Iphone CLLocation获取EXC\u错误\u访问,iphone,mkmapview,Iphone,Mkmapview,我在尝试访问CLLocation时出错,您能解释一下原因吗 CLLocation *currentLocation; @property (nonatomic, retain) CLLocation *currentLocation; 我正在从位置经理那里获得位置反馈: - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(

我在尝试访问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);
    }
}
位置经理:+/-100.00m(速度-1.00mps/航向-1.00)@9/2/11 10:14:58 π.μ. 格林尼治时间+02:00

但当我试图从DidSelectAnnotationView访问currentLocation时,我获得了EXC\u BAD\u访问权限:

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

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

}
你能解释一下为什么我不能访问它吗


非常感谢

您没有保留该位置。像这样做:

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

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

您没有保留该位置。像这样做:

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

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