问题
I want to be able to track the coordinates of my MKAnnotation
as I drag it. Currently, I am only getting the coordinates as the drag begins.
I have tried implementing a custom MKAnnotationView
subclass with touchesMoved
, however this appears not to work. (As suggested here: Obtaining MKAnnotation's coordinate while dragging.)
By receiving the new coordinates as I drag my annotation, I will in turn be able to update my polygon shape.
回答1:
You can track the coordinates from MKAnnotationView
.
When your view is dragged.The following delegate gets called.
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState
In that you can use :
if (newState == MKAnnotationViewDragStateDragging) {
CLLocationCoordinate2D location = [_polyMapView convertPoint:view.center toCoordinateFromView:view.superview];
}
Here _polyMapView
would be your mapView and view
would be your annotation view.This would get you the current coordinates of the Annotation.
来源:https://stackoverflow.com/questions/35048583/seeing-mkannotation-coordinates-during-drag