使用 MKPinAnnotationView 和 MKAnnotationView 更新用户位置

User location update with MKPinAnnotationView and MKAnnotationView

知道为什么会出现以下情况:

    let reuseId = "pin"
    var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
    pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
    pinView!.annotation = annotation
    pinView!.canShowCallout = false
    pinView!.draggable = true

允许在以下情况下快速回到用户位置的可拖动注释:

    let reuseId = "pin"
    var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
    pinView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
    pinView!.annotation = annotation
    pinView!.canShowCallout = false
    pinView!.draggable = true

不快速回到用户位置。

这是在 viewForAnnotation 函数中实现的,它允许您更改当前位置图钉。

我正在尝试编辑用户位置的图钉,我希望它可以拖动,但我希望它在完成拖动后快速回到用户位置。它只在 MKPinAnnotationView 中执行,但我需要它为 MKAnnotatioView 工作。感谢您的帮助!

不幸的是,我认为这正是子类的实现方式。

我认为解决方法是使用类似的东西:

- (void)mapView:(MKMapView *)mapView 
        annotationView:(MKAnnotationView *)annotationView 
        didChangeDragState:(MKAnnotationViewDragState)newState 
        fromOldState:(MKAnnotationViewDragState)oldState 
{
    if (newState == MKAnnotationViewDragStateEnding)
    {
        //reset CLLocationCoordinate2D of MKAnnotation to the old coordinate (i.e. where the annotation view was before dragging)
    }
}

请注意,我认为要刷新注释,您可能需要删除注释并重新添加。这些图钉更容易管理,但我知道它们不那么容易定制。