Can anyone provide any sample code/instructions for implementing draggable pins in OS 4.0 using the MapKit framework?
+2
A:
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.
Tristan
2010-07-07 03:44:02
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
2010-08-20 08:59:29
A:
Check out MapKitDragAndDrop by Ching-Lang Huang and the author's accompanying blog post.
Joost Schuur
2010-07-08 09:23:35