ドラッグ可能なアノテーションのコールアウト情報に問題があります.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;
}
任意のアイデアは?
ありがとうございます!
ありがとうございました。これは機能します。古いコールアウトが表示されてすぐに消えるのは、おそらく最も洗練されたソリューションではありませんが、情報を更新しない方が良いです。不思議なもの: - (void)mapView:(MKMapView *)annotationView(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState;などの他のデリゲート関数でこれらの選択と選択解除メソッドを使用しようとしました。それは効果がなかった!なぜなのかご存知ですか ? – Johanisma
私は私の解決策が最高ではないことに同意します! 私は実際には悪い解決策を投稿して答えを編集しました^ _ ^、私は「削除」してから、注釈自体をmapViewから選択してから選択しました... まあ、同じことはできませんdidChangeDragStateメソッド! これは単にコールアウト情報がまだ変更されていないためです。 didFindPlacemarkメソッドでのみ変更されました;) –