iOS6で緯度と経度を取得 didUpdateLocations
緯度と経度をとりたいと思って、「よくわかるiPhoneアプリ開発の教科書」を写経してたら、iOS6からdidUpdateToLocationメソッドが使えなくなっていたので、代替のdidUpdateLocationsを使いましたという話。
日本語のソースがなかったので残します。
実機では試していませんが、シミュレーターではうまくいきました。
ぐぐってみると代わりにdidUpdateLocationsを使うようにとのこと。
公式リファレンスを参考にして以下のようになりました。
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ CLLocation *location = [locations objectAtIndex:0]; _latLabel.text = [NSString stringWithFormat:@"緯度%f",location.coordinate.latitude]; _logLabel.text = [NSString stringWithFormat:@"軽度%f", location.coordinate.longitude]; }