【问题标题】:Reverse Geocoding on MKMapView by dragging Pins通过拖动 Pins 在 MKMapView 上反向地理编码
【发布时间】:2011-05-19 04:30:00
【问题描述】:

我有一个 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];

    }
}

任何帮助都会很棒。最后,地图应用程序是通过拖动来实现这一点的最佳示例。

【问题讨论】:

    标签: iphone drag-and-drop mkmapview mkpinannotationview mkreversegeocoder


    【解决方案1】:

    我想通了。

    由于 KVO,我必须设置 Location 对象的字幕。所以它会显示出来。

    但是因为字幕是由

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

    我只需要在我的 NSManagedObject 子类中执行以下操作。

    - (void) setSubtitle:(NSString *)title{ //do nothing}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多