2011-03-08 5 views
0

`안녕하세요. 항상 0을 반환하는 distanceFromLocation 메서드를 사용할 때 문제가 있습니다.CLLocation distanceFromLocation 항상 0을 반환합니다.

여기 내 코드입니다 : -6.17503957 긴 : 106.79891717 및 currentLoc 가치는 위도이다 나는 또한 branchLoc을 확인하고 currentLoc 인스턴스가 여기에 올바른 값 있다 branchLog 위도의 예 값입니다

NSArray *arrATMItem = [arrATMs objectAtIndex:indexPath.row]; 
cell.textLabel.text = [arrATMItem objectAtIndex:0]; 

float lat = [[arrATMItem objectAtIndex:1] floatValue]; 
float lon = [[arrATMItem objectAtIndex:2] floatValue]; 
CLLocation *branchLoc = [[CLLocation alloc] initWithLatitude:lat longitude:lon]; 

CLLocationDistance dist = [currentLocation distanceFromLocation:branchLoc]; 
NSLog(@"distance = %d",dist); 
cell.detailTextLabel.text = [[NSString alloc] initWithFormat:@"%d m", dist]; 

: -6.17603957 long : 106.79891717

branchLoc 값은 plist 파일에서 가져오고 currentLoc은 내 위임 파일에 정의 된 CLLocation locationUpdate 메소드의 CLLocation 클래스에서 가져옵니다.

나는 % f를 사용해 보았고, 0.00000 내가 잘못하고있는 어떤 생각을 되 돌렸을 까?

감사합니다.

+0

나는이 일이 내게 일어났기 때문에 다른 사람들을 위해이 덧글을 추가하고 있습니다. 내가 만든 테스트 위치를 사용하고있었습니다. 그러나, 그들은 유효하지 않았다 (나는 위도와 경도를 뒤섞었다). 'CLLocationCoordinate2DIsValid (currentLocation.coordinate) '함수를 사용하여 좌표가 유효한지 아닌지를 결정할 수있다. – Roberto

답변

0

lat 및 lon에 double (또는 CLLocationDegrees)을 사용해보십시오.

관련 문제