当我有一个CLLocation我下面的函数应用崩溃访问CLLocation
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation{
currentLocation = newLocation;
}
内设置为当前位置。当我试图访问在以后的方法中的当前位置的应用程序崩溃。
NSLog(@"current latitude is %f", currentLocation.coordinate.latitude);
NSString *longitude = [NSString stringWithFormat:@"%g", currentLocation.coordinate.longitude];
NSString *latitude = [NSString stringWithFormat:@"%g", currentLocation.coordinate.latitude];
当前位置在第一个方法中设置。我可以打印出来,奇怪的是,我将这个currentLocation定义为标题中的指针。
该应用程序崩溃,没有堆栈跟踪。调试器只是发送给我的应用程序的retValue。
我试图在设置到newLocation之前保留指针和alloc,但似乎没有任何工作。
我缺少的是:d
如果您使用%f而不是%g,该怎么办?或者尝试使currentLocation属性,所以你会有'self.currentLocation'而不是? – 2011-05-27 01:48:26
如何在你的.h文件中声明'currentLocation'? – 2011-05-27 01:54:56
CLLocation * currentLocation; @property(nonatomic,retain)CLLocation * currentLocation; – jarryd 2011-05-27 01:57:12