1

I have a subclass "Location" of NSManagedObject and this class conforms to MKAnnotation.

When I add a Location to a Map...the ReverseGeocoder starts. By clicking the pin I see in the callout View the address of the pin. So everything works fine.

Now my problem.

I am able to drag the pins. When I am finished dragging, than again the ReverseGeocoder starts to ask for location Data. But I still have the old address in the callout view, although the placemarks are updated in the Location object. After dragging again I can see the new address. (of course the new one isn't new anymore, because I dragged).

Here is my code for the dragging state:

- (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];
}

And the Code for my reverse geocoder delegate

- (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];

    }
}

Any help would be wonderful. In the end the Maps App is best example for doing that by dragging.

lordgil
  • 33
  • 4

1 Answers1

2

I figured out.

Because of KVO I hust hace to set the subtitle of the Location object. So it gets displayed.

But because the subtilte is generated by

// Associate the placemark with the annotation.
theAnnotation.city = [place locality];
theAnnotation.zipcode = [place postalCode];
theAnnotation.street = [place thoroughfare];

I just had to do the following in my NSManagedObject Subclass.

- (void) setSubtitle:(NSString *)title{ //do nothing}
lordgil
  • 33
  • 4