2011-01-15 7 views
0

ドラッグ可能なアノテーションのコールアウト情報に問題があります.MKReverseGeocoderを使用して、アノテーションの位置に対応する座標のアドレスを取得します。iOSを使用したドラッグ可能なアノテーション:コールアウト情報の更新

私は制御できないものがあります:ドラッグ可能な注釈が削除されるたびに、吹き出し情報が表示されます。非常に頻繁に、MKReverseGeocoderはこれが起こる前にアドレス情報を更新する時間がありませんでした。そのような通常の場合、アノテーションの吹き出しは、アノテーションの前の座標に対応するアドレス情報を表示します。

ここコードである:

1)、注釈がドロップされるときに呼び出されるデリゲートメソッド:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState{ 
     if (oldState == MKAnnotationViewDragStateDragging) { 
      MKReverseGeocoder *reverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:annotationView.annotation.coordinate]; 
      reverseGeocoder.delegate = self; 
      [reverseGeocoder start]; 
      while (reverseGeocoder.querying) { 
       [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; 
      } 
      [reverseGeocoder release]; 
     } 
    } 

2)reverseGeocoderが答えを見つけたときに呼び出されるデリゲートメソッド:

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark { 
    NSString *newSubtitle = [NSString stringWithFormat:@"%@ %@, %@ %@, %@",placemark.subThoroughfare,placemark.thoroughfare,placemark.postalCode,placemark.locality, placemark.country]; 
    Grocery *draggableGrocery = [myMapView.annotations objectAtIndex:0]; 
    draggableGrocery.address = newSubtitle; 
    self.addressNewGrocery = newSubtitle; 
} 

任意のアイデアは?

ありがとうございます!

答えて

0

私は同じ質問を投稿していましたが、私は昨日から同じ問題を探していました。


UPDATE:


私はちょうど方法を考え出した、と私はそれが正しいものであるかはわかりません。 didFindPlacemark機能:

[mapView deselectAnnotation:selectedAnnotation animated:NO]; 
[mapView selectAnnotation:selectedAnnotation animated:NO]; 

をあなたのケースのためにあなたのコードは次のようになります。私はrevereseGeocoderで新しいタイトルを得た後、私はselectedAnnotationと呼ばれるMKAnnotationサブクラスは、私が単に選択解除し、そのオブジェクトが選択されていることを知ります:

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark { 
    NSString *newSubtitle = [NSString stringWithFormat:@"%@ %@, %@ %@, %@",placemark.subThoroughfare,placemark.thoroughfare,placemark.postalCode,placemark.locality, placemark.country]; 
    Grocery *draggableGrocery = [myMapView.annotations objectAtIndex:0]; 
    draggableGrocery.address = newSubtitle; 
    self.addressNewGrocery = newSubtitle; 
    // add the following lines [I assumed that draggableGrocery [Grocery class] is a subclass of MKAnnotation] 
    [mapView deselectAnnotation:draggableGrocery animated:NO]; 
    [mapView selectAnnotation:draggableGrocery animated:NO]; 
} 
+0

ありがとうございました。これは機能します。古いコールアウトが表示されてすぐに消えるのは、おそらく最も洗練されたソリューションではありませんが、情報を更新しない方が良いです。不思議なもの: - (void)mapView:(MKMapView *)annotationView(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState;などの他のデリゲート関数でこれらの選択と選択解除メソッドを使用しようとしました。それは効果がなかった!なぜなのかご存知ですか ? – Johanisma

+1

私は私の解決策が最高ではないことに同意します! 私は実際には悪い解決策を投稿して答えを編集しました^ _ ^、私は「削除」してから、注釈自体をmapViewから選択してから選択しました... まあ、同じことはできませんdidChangeDragStateメソッド! これは単にコールアウト情報がまだ変更されていないためです。 didFindPlacemarkメソッドでのみ変更されました;) –

0

別のオプションは、ちょうど逆ジオコーダを開始する前にannotationView.canShowCallout = NOを設定し、終了したらYESに戻すフラグを設定することです。

関連する問題