【问题标题】:(iPhone) how to implement draggable pins using OS 4.0 MapKit?(iPhone) 如何使用 OS 4.0 MapKit 实现可拖动引脚?
【发布时间】:2011-03-12 15:03:41
【问题描述】:

谁能提供任何使用 MapKit 框架在 OS 4.0 中实现可拖动引脚的示例代码/说明?

【问题讨论】:

    标签: iphone mapkit draggable mkmapview drag


    【解决方案1】:

    当然,伙计(是的,我是在自言自语),

    在您的自定义注释中添加:

    @property (nonatomic, readwrite, assign) CLLocationCoordinate2D coordinate; 
    

    这满足了实现setCoordinate的要求,如http://developer.apple.com/iphone/library/documentation/MapKit/Reference/MKAnnotationView_Class/Reference/Reference.html#//apple_ref/occ/instp/MKAnnotationView /可拖动

    在您的 MapView 委托中添加:

    - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState 
    {
    //..Whatever you want to happen when the dragging starts or stops
    }
    

    并在您的 AnnotationView 中将 draggable 设置为 true,例如:

    customAnnotationView.draggable      = YES;
    

    我认为这就是我为使其正常工作所做的一切。有问题请告诉我。

    【讨论】:

    • 我正在使用“更多 iPhone 开发”一书中的自定义注释类“MapLocation”——它是一个普通的自定义注释类。我添加了 ,assign 到现有属性以使其像上面一样,但从不调用拖动回调。在 viewForAnnotation 中,我将注解转换为 MapLocation 并获取其视图并设置 draggable=YES。我这样做只是为了测试,我可能会支持 OS3。但是您知道可能缺少什么吗?
    • Tristan 你愿意分享你用来让它工作的代码吗?我正在做我能想到的所有事情,但由于某种原因,我无法让别针移动,我已经尝试了所有我能找到的教程(包括下面的评论)。谢谢!
    【解决方案2】:

    查看 MapKitDragAndDrop by Ching-Lang Huang 和作者随行的 blog post

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-18
      • 1970-01-01
      • 2012-04-14
      • 2023-03-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多