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

データベースからのオブジェクト: long: 59.291114 lat: 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 に答える