2012-01-07 8 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

コードは私のためにバットのまっすぐに動作します。単一のビューアプリケーションで。あなたの現在の場所を使用するように求められたら、[OK]をクリックしましたか? – markhunte

+0

ああ、私はiOS5を使用していたことを認識しました。あなたは取得しています:サーバーはクライアントの登録を受け付けませんでした68.コンソールで – markhunte

答えて

0

コードは正常です。それがうまくいかない場合、問題はここにはありません。

ていることを確認してください:

  1. あなたはデバイス上でそれを実行している(エミュレータではない)
  2. お使いのデバイスは、SIMが
  3. をインストールし、携帯電話ネットワークに接続されたそれは、無線LANに接続されたデバイスを持っていることは非常に良い考えですインターネットにアクセスできます。

これらすべては、GPSが補助GPSを使用してより速く位置を固定するのに役立ちます。

また、Core Locationが直ちに最後の既知の位置を返すことを考慮してください。それは古くて間違っているかもしれませんが、すぐに提供されます。何も得られない場合は、アプリケーションではなく、デバイス上のコアロケーションに関する問題のように見えます。

また、可能なエラーをキャッチするために、locationManager:didFailWithError:メソッドを実装することをお勧めします。無効にしたGPSのように。

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

GPS位置固定が3GSのために数分かかり、早期、及び4と4Sのために約10秒(両方の場合で晴天の眺めを仮定して)もよい

+0

ログは、エラー:エラー:エラードメイン= kCLErrorDomainコード= 0 "操作を完了できませんでした。(kCLErrorDomain error 0.) – user1112600