0

基于视图的应用程序,

.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

4

2 回答 2

4

使用distanceFromLocation:代替

于 2010-05-29T20:59:47.067 回答
2

CurrentLocation实例变量/属性吗?您在没有访问器的情况下直接设置它,并且您没有保留它。如果在您使用它之前释放getDistance:它会导致崩溃。

如果它是一个属性,请使用self.CurrentLocation来确保它被保留。

另外,施工...

NSLog([NSString stringWithFormat:@"%.0f", distance]);

...是有风险和多余的。采用...

NSLog(@"%.0f", distance);

... 反而。

于 2010-02-09T19:40:46.443 回答