2011-03-25 6 views
0

CLLocationCoordinate2D를 보유하는 클래스가 있습니다. 웹 요청으로 위도가 &입니다.CLLocationDegrees는 값이 있지만 0을 반환합니다.

CLLocationCoordinate2D 개체를 사용하여지도 (MKMapView)에 개체를 놓을 때 모든 것이 올바르게 작동합니다.

하지만 CLLocationCoordinate2D의 위도 또는 경도 (CLLocationDegrees)를 다른 변수와 비교하거나 문자열에 넣으려고하면 값이 정확하더라도 항상 0 (영)을 얻습니다. 35.0333 .. 등) 예를 들어

:

item.coordinate.latitude입니다 32.816326141357422

(지도 객체를 놓을 때 나는 또한 올바른 디버깅하는 동안 항목을 내 커서를 놓고, 때 표시)

NSLog (@ "lat : % f", item.coordinate.latitude); =>이 "lat : 0"을 출력합니다.

NSString * lats = [[NSNumber numberWithDouble : item.coordinate.latitude] stringValue]; =>이 부분은 "0"이됩니다.

누구든지이 문제를 해결하는 방법을 알고 있습니까? 덕분에 .

+0

실제 코드를 게시하면 오류가있는 곳을 쉽게 찾아 낼 수 있습니다. –

+0

URL 요청을 암호화 했습니까? – Lokus001

답변

0

대신

NSLog(@"lat: %f", item.coordinate.latitude); 

는 시도 :

또한
if (![[NSString stringWithFormat:@"%+.6f,%+.6f", locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude] isEqualToString:@"+0.000000,+0.000000"]) 
{ 
    // do cool stuff 
} 

있는지 확인 당신은 위임하고 위임 방법을 설정 한 :

NSLog(@"lat: %+.6f", item.coordinate.latitude); 

나는 다음과 같은 것을 사용 귀하의 CLLocationManager :

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    locationManager = [[CLLocationManager alloc] init]; 
    [locationManager setDelegate:self]; 
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest]; 
    [locationManager setDistanceFilter:kCLDistanceFilterNone]; 
    if (locationManager.locationServicesEnabled) 
     [locationManager startUpdatingLocation]; 
} 

#pragma mark - 
#pragma mark CLLocationManager Delegate Methods 

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{ 
    NSDate* eventDate = newLocation.timestamp; 
    NSTimeInterval howRecent = [eventDate timeIntervalSinceNow]; 
    if (abs(howRecent) < 15.0) 
    { 
     NSLog(@"New Latitude %+.6f, Longitude %+.6f", newLocation.coordinate.latitude, newLocation.coordinate.longitude); 
    } 
} 
+0

... @taxman 는 위도 및 경도가 아니라 플로트에 대하여 테스트 될 수 밝혀 : 경우 (fabsf (locationManager.location.coordinate.latitude)> 0.0) {...} 경우 (fabsf (을 locationManager한다. location.coordinate.longitude)> 0.0) {...} – chown

관련 문제