(iPhone) how to implement draggable pins using OS 4.0 MapKit?

北战南征 提交于 2019-11-29 08:21:35

问题


Can anyone provide any sample code/instructions for implementing draggable pins in OS 4.0 using the MapKit framework?


回答1:


Sure thing buddy (yes I'm talking to myself),

In your custom annotation add:

@property (nonatomic, readwrite, assign) CLLocationCoordinate2D coordinate; 

This satisfies the requirement of implementing setCoordinate, as mentioned inhttp://developer.apple.com/iphone/library/documentation/MapKit/Reference/MKAnnotationView_Class/Reference/Reference.html#//apple_ref/occ/instp/MKAnnotationView/draggable

In your MapView delegate add:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState 
{
//..Whatever you want to happen when the dragging starts or stops
}

and in your AnnotationView set draggable to true, so for example:

customAnnotationView.draggable      = YES;

I think that was everything that I did to get it working. Tell me if you have troubles.




回答2:


Check out MapKitDragAndDrop by Ching-Lang Huang and the author's accompanying blog post.



来源:https://stackoverflow.com/questions/3191728/iphone-how-to-implement-draggable-pins-using-os-4-0-mapkit

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