ios - 我如何在 MKmapView 中拖动我的注释,就像 Google Pin Drop 和 Dragging :iOS

标签 ios objective-c annotations mkmapview

我需要一些帮助。我如何在 MKMapview 中将注释( map 图钉)从一个点拖到另一个点。 在 map 上下拉图钉后,添加过程一切顺利,我想拖动那个图钉(注释)并像谷歌地图一样改变那个地方。

快乐编码

最佳答案

首先允许pin拖动

- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id) annotation 
{ 
    pin.draggable = YES; 
}

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

}

关于ios - 我如何在 MKmapView 中拖动我的注释,就像 Google Pin Drop 和 Dragging :iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36590554/

相关文章:

ios - 是否仍然可以在 iOS 和 tvOS 之间共享 UserDefaults?

ios - 将立方体变成球体

objective-c - 将添加了叠加层的照片保存到照片库

iphone - UITextField 字体样式没有改变

java - Hibernate注解字段定义

hibernate - @GenerateValue with Strategy=GenerationType.AUTO 重启后生成重复值

ios - 如何使整个调用可点击?

ios - 使用具有网关保护的 JSON Webservice 时 IOS 无响应

ios - UIKeyboardWillShow/WillHide 通知,如何知道这些通知何时发送给已注册的观察者

ios - 在 UIPageIndicator 下面添加 UIButton