NSManagedObject의 하위 클래스 인 "위치"가 있으며이 클래스는 MKAnnotation을 준수합니다.핀을 드래그하여 MKMapView에서 지오 코딩을 역방향으로 수행
위치를지도에 추가하면 ReverseGeocoder가 시작됩니다. 설명 선에 표시되는 핀을 클릭하여 핀의 주소를 봅니다. 그래서 모든 것이 잘 작동합니다.
이제 내 문제.
핀을 끌 수 있습니다. 드래그가 끝나면 ReverseGeocoder가 다시 위치 데이터를 요청하기 시작합니다. 위치 표시 개체가 위치 개체에서 업데이트되었지만 콜 아웃보기에 여전히 이전 주소가 있습니다. 다시 드래그 한 후 새 주소를 볼 수 있습니다. (물론 내가 끌었 기 때문에 새로운 것이 더 이상 새 것이 아닙니다.)
- (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];
}
}
어떤 도움이 멋진 것에 대한 코드 :
여기 내 드래그 상태에 대한 코드입니다. 결국지도 앱을 드래그하여 가장 좋은 예가됩니다.