문제

기반 앱보기,

.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

도움이 되었습니까?

해결책

~이다 CurrentLocation 인스턴스 변동/속성? 액세서없이 직접 설정하고 있으며 유지하지 않습니다. 사용하기 전에 릴리스 된 경우 getDistance: 충돌이 발생합니다.

속성 인 경우 사용하십시오 self.CurrentLocation 유지되도록 보장합니다.

또한 건축 ...

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

... 위험하고 중복됩니다. 사용...

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

... 대신에.

다른 팁

사용 DistoneFromLocation : 대신에

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top