Can anyone suggest a good tutorial for implementing dragging feature for MKPinAnnotationView
in iPhone MKMapView
?
Asked
Active
Viewed 2,662 times
0

MCKapur
- 9,127
- 9
- 58
- 101

Tinku George
- 195
- 2
- 11
-
Duplicate of: http://stackoverflow.com/questions/11927692/ios-mkmapview-draggable-annotations and many others – MCKapur Dec 24 '12 at 05:21
2 Answers
4
you can find source code demo for MKPinAnnotationView Drag & drop feature from this link.
Update: The Github project link given in above site url is not working. But I found new project example for that from this url.

Jagat Dave
- 1,643
- 3
- 23
- 30

Sunil Zalavadiya
- 1,993
- 25
- 36
3
To make an annotation draggable, set the annotation view's draggable property to YES.
This is normally done in the viewForAnnotation delegate method so make sure you set the MKMapView
delegate to self
and conform to it in the .h file.
For example:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString *reuseId = @"pin";
MKPinAnnotationView *pav = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseId];
if (pav == nil)
{
pav = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId];
pav.draggable = YES; // Right here baby!
pav.canShowCallout = YES;
}
else
{
pav.annotation = annotation;
}
return pav;
}
Ok, so here is the code to manage a annotations drag action:
- (void)mapView:(MKMapView *)mapView
annotationView:(MKAnnotationView *)annotationView
didChangeDragState:(MKAnnotationViewDragState)newState
fromOldState:(MKAnnotationViewDragState)oldState
{
if (newState == MKAnnotationViewDragStateEnding) // you can check out some more states by looking at the docs
{
CLLocationCoordinate2D droppedAt = annotationView.annotation.coordinate;
NSLog(@"dropped at %f,%f", droppedAt.latitude, droppedAt.longitude);
}
}
This should help!

MCKapur
- 9,127
- 9
- 58
- 101