Seeing MKAnnotation Coordinates During Drag

女生的网名这么多〃 提交于 2019-12-25 03:14:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!