Draggable Pin does not have a fixed position on the map

I am currently implementing a function in which the user can manually manually copy to the map. I set annotationView to annotationView.draggable = YES;, and I also applied the delegate method to get the new coordinates. But how can I now tell mapView that the drag action should stop now, and the pin gets a fixed position on the map, even if the map is moving.

The current behavior is that after dragging a pin to a new position, if I then move the map, the contact has a fixed position only on the device’s screen, but not on the map.

Help is appreciated :).

Delegate:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState
{
    if (newState == MKAnnotationViewDragStateEnding)
    {
        CLLocationCoordinate2D droppedAt = annotationView.annotation.coordinate;
        NSLog(@"Pin dropped at %f,%f", droppedAt.latitude, droppedAt.longitude);
    }
}
+1
1

UPDATE:

ok, :

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState
{
    if (newState == MKAnnotationViewDragStateStarting)
    {
        annotationView.dragState = MKAnnotationViewDragStateDragging;
    }
    else if (newState == MKAnnotationViewDragStateEnding || newState == MKAnnotationViewDragStateCanceling)
    {
        annotationView.dragState = MKAnnotationViewDragStateNone;
    }
}

, . , ..:

MKAnnotationViewDragStateStarting, MKAnnotationViewDragStateDragging. , , YES, .

MKAnnotationViewDragStateCanceling MKAnnotationViewDragStateEnding, MKAnnotationViewDragStateNone. , - , .

+4

Source: https://habr.com/ru/post/1543399/


All Articles