基于视图的应用程序,
.m
- (void)viewDidLoad {
[super viewDidLoad];
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate = self;
[[self locationManager] startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
CurrentLocation = newLocation;
[locationManager stopUpdatingLocation];
myActivity.hidden=YES;
[self reStart];
}
-(void)reStart{
[self checkAndCreateDatabase]; //Sucess
[self readFromDatabase]; //Success if I comment the get distance part
[self sort]; //Success
}
-(void) readFromDatabase {
...
CLLocationCoordinate2D cord;
cord.latitude = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)] doubleValue];
cord.longitude =[[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)] doubleValue];
NSDate *today = [NSDate date];
CLLocation *objectLocation = [[CLLocation alloc] initWithCoordinate:cord altitude:1 horizontalAccuracy:1 verticalAccuracy:-1 timestamp:today];
CLLocationDistance distance = [objectLocation getDistanceFrom:CurrentLocation]/1000;
NSLog([NSString stringWithFormat:@"%.0f", distance]);
}怎么啦?
调试器说:
obj_msgSend
0x912e8688 <+0024> mov 0x20(%edx),%edi来自数据库的对象:长整型: 59.291114长整型: 17.816191
发布于 2010-02-10 03:40:46
CurrentLocation是实例变量/属性吗?您正在不使用访问器的情况下直接设置它,并且不会保留它。如果在getDistance:中使用它之前就将其释放,将会导致崩溃。
如果它是一个属性,则使用self.CurrentLocation来确保它被保留。
还有建筑..。
NSLog([NSString stringWithFormat:@"%.0f", distance]);..。是危险和多余的。使用...
NSLog(@"%.0f", distance);..。而不是。
发布于 2010-05-30 04:59:47
请改用distanceFromLocation:
https://stackoverflow.com/questions/2231584
复制相似问题