NSManagedObjectのサブクラス「Location」があり、このクラスはMKAnnotationに準拠しています。
地図に場所を追加すると...ReverseGeocoderが起動します。コールアウトに表示されているピンをクリックして、ピンのアドレスを表示します。したがって、すべてが正常に機能します。
今私の問題。
ピンをドラッグできます。ドラッグが終了すると、ReverseGeocoderは位置データを要求し始めます。ただし、Locationオブジェクトで目印が更新されていますが、コールアウトビューにはまだ古いアドレスがあります。もう一度ドラッグすると、新しいアドレスが表示されます。(もちろん、ドラッグしたので、新しいものはもう新しいものではありません)。
ドラッグ状態のコードは次のとおりです。
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState{
//if dragging ended
if (newState == MKAnnotationViewDragStateNone && oldState == MKAnnotationViewDragStateEnding) {
CLLocation *location = [[CLLocation alloc] initWithLatitude:annotationView.annotation.coordinate.latitude longitude:annotationView.annotation.coordinate.longitude];
[self geocodeLocation:location forAnnotation:annotationView.annotation];
[location release];
}
そして、私の逆ジオコーダーデリゲートのコード
- (void)reverseGeocoder:(MKReverseGeocoder*)geocoder didFindPlacemark:(MKPlacemark*)place
{
Location* theAnnotation = [self.map annotationForCoordinate:place.coordinate];
if (!theAnnotation)
return;
// Associate the placemark with the annotation.
theAnnotation.city = [place locality];
theAnnotation.zipcode = [place postalCode];
theAnnotation.street = [place thoroughfare];
DEBUGLOG(@"Place: %@", place);
// Add a More Info button to the annotation's view.
MKPinAnnotationView* view = (MKPinAnnotationView*)[self.map viewForAnnotation:theAnnotation];
if (view)
{
DEBUGLOG(@"SUBTITLE: %@", theAnnotation.subtitle);
view.leftCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
}
どんな助けでも素晴らしいでしょう。結局、マップアプリはドラッグしてそれを行うための最良の例です。