質問

ビューベースのアプリケーション、

.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

役に立ちましたか?

解決

CurrentLocationインスタンス変数/プロパティですか?あなたはアクセサせずに直接それを設定している、あなたはそれを保持されていません。あなたはgetDistance:でそれを使用する前に、それが解放された場合には、クラッシュの原因となります。

それは財産である場合は、それが保持されていることを確認するためにself.CurrentLocationを使用しています。

また、建設...

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

...リスキーかつ冗長です。使用して...

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

...代わりに。

他のヒント

を使用するの distanceFromLocation:の代わりに

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top