Can anyone provide any sample code/instructions for implementing draggable pins in OS 4.0 using the MapKit framework?
Asked
Active
Viewed 5,649 times
2 Answers
14
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.

WoodenKitty
- 6,521
- 8
- 53
- 73
-
I'm using the custom annotation class "MapLocation" from the book "More iPhone Development" - it's a normal custom annotation class. I added ,assign to the existing property to make it like above, but the drag callback is never invoked. In viewForAnnotation I cast the annotation as a MapLocation and fetched its view and set draggable=YES. I did it just for testing, I will probably go with OS3 support. But do you have an idea what could be missing? – Henrik Erlandsson Aug 20 '10 at 08:59
-
Tristan would you be willing to share the code you used to get it woking? I am doing everything I can think of but for some reason I cannot get the pin to move and I have tried every tutorial out there I could find (including the comment below). Thank you! – Kinetic Stack Apr 25 '12 at 17:20
1
Check out MapKitDragAndDrop by Ching-Lang Huang and the author's accompanying blog post.

Joost Schuur
- 4,417
- 2
- 24
- 39