cllocation と mkreversegeocoder で都市名を取得しようとしています。私のviewdidloadメソッドでは、インスタンスcllocationmanager:
self.locManager = [[CLLocationManager alloc] init];
locManager.delegate = self;
locManager.desiredAccuracy = kCLLocationAccuracyBest;
[locManager startUpdatingLocation];
以降:
- (void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation
*)newLocation
fromLocation:(CLLocation *)oldLocation {
//some code to retrieve my information
MKReverseGeocoder *geoCoder = [[MKReverseGeocoder alloc]
initWithCoordinate:newLocation.coordinate ];
geoCoder.delegate = self;
[geoCoder start];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark
*)placemark
{
MKPlacemark *myPlacemark = placemark;
citta.text = [placemark locality];
}
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{
citta.text =@ "Unknow";
アプリケーションは、値を初めて取得したときにのみ機能します。2 回目のアプリのクラッシュ時。ジオコーダーが開始されたためだと思います。実行中のインスタンスは1つだけである必要があると思います。(しかし、私は本当にこれについて確信が持てません...)。ジオコーダーの実行をどのように制御できますか?
cllocationcoordinate2d を使用して viewdidload で mkreversegeocoder をインスタンス化できることがわかりましたが、どのようにして newlocation.coordinate を取得できますか?
ジオコーダーをクラス変数として宣言してチェックすることを部分的に解決しました
if (self.geocoder != nil) {
[geocoder release];
}
しかし....私の場合
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark
*)placemark
または私の
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailedWithError:(@NSError
*)error
オブジェクトをリリースまたはキャンセルしますか? 私はとてもばかげていると感じています:D