2012-01-07 4 views
0

저는 http://www.switchonthecode.com/tutorials/getting-your-location-in-an-iphone-application 자습서를 따르고 있습니다.하지만 Xcode SDK에서 위도와 경도를 구할 수 없습니다.위도 경도 IOS 4.3

- (void)viewDidLoad { 
[super viewDidLoad]; 
locationManager = [[CLLocationManager alloc] init]; 
locationManager.delegate = self; 
[locationManager startUpdatingLocation]; 

} 


- (void)locationManager:(CLLocationManager *)manager 
didUpdateToLocation:(CLLocation *)newLocation 
     fromLocation:(CLLocation *)oldLocation 
{ 

int degrees = newLocation.coordinate.latitude; 
double decimal = fabs(newLocation.coordinate.latitude - degrees); 
int minutes = decimal * 60; 
double seconds = decimal * 3600 - minutes * 60; 
NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"", 
       degrees, minutes, seconds]; 
//latLabel.text = lat; 
degrees = newLocation.coordinate.longitude; 
decimal = fabs(newLocation.coordinate.longitude - degrees); 
minutes = decimal * 60; 
seconds = decimal * 3600 - minutes * 60; 
NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"", 
        degrees, minutes, seconds]; 
NSLog(@"%@ %@",longt, lat); 

} 

콘솔에서 위도와 경도를 표시하지 않습니다. 도와주세요.

+1

: 여기

이 방법의 예는 델리게이트 메소드'locationManager : didFailWithError :'를 구현하고 있습니까? 그렇다면 오류가 있습니까? 그렇지 않다면 구현하고 오류가 있는지 확인하십시오. – mattjgalloway

+0

코드는 바로 나를 위해 박쥐에서 작동합니다. 단일보기 앱에서. 앱에서 현재 위치를 사용하도록 요청하면 확인을 클릭 했습니까? – markhunte

+0

아, 방금 iOS5를 사용하고 있다는 것을 깨달았습니다. 당신은 점점 : 서버가 클라이언트 등록을 받아들이지 않았습니다. 68. 콘솔에서 – markhunte

답변

0

코드가 정상적으로 보입니다. 작동하지 않으면 여기에 문제가 없습니다.

확인 :

  1. 을 당신은 장치에서 실행 그것은 무선 랜에 연결된 장치가 매우 좋습니다
  2. 귀하의 장치는 SIM 설치 및 셀룰러 네트워크
  3. 으로 연결 (에뮬레이터되지 않음) 인터넷 접속.

이 모든 것들이 GPS가 보조 GPS를 사용하여 더 빨리 위치를 고정하는 데 도움이됩니다.

또한 코어 위치가 가장 최근의 알려진 위치를 즉시 반환한다는 점을 고려하십시오. 그것은 오래되어 잘못되었을 수도 있지만 즉시 제공됩니다. 전혀 얻지 못하면 응용 프로그램이 아니라 장치의 코어 위치 문제와 유사합니다.

또한 가능한 오류를 잡기 위해 locationManager : didFailWithError : 메소드를 구현하는 것이 좋습니다. 비활성화 된 GPS와 같습니다.

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{ 
NSLog(@"GPS Error: %@", [error localizedDescription]); 
} 

GPS 위치 고정이 3gs를 위해 몇 분 걸릴 초, 4와 4S를위한 약 10 초 (두 경우 맑은 하늘보기 가정) 수

+0

로그가 다음을 표시합니다. 오류 : 오류 : 오류 도메인 = kCLErrorDomain 코드 = 0 "작업을 완료 할 수 없습니다. (kCLErrorDomain 오류 0.)"어떤 아이디어 ?? – user1112600