I am trying to implement drag/drop annotation on map. Initially the pin is dropped at user's current location which i do with [self.mapView setShowsUserLocation:YES];
but when i drag and drop the pin it returns back to the current location after some time.
Here is the code:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize mapView;
- (void)viewDidLoad {
[super viewDidLoad];
mapView.delegate = self;
}
- (MKAnnotationView *)mapView:(MKMapView *)mv viewForAnnotation:(id <MKAnnotation>)annotation
{
//MKAnnotationView* annotationView = nil;
MKAnnotationView *annotationView = [mv dequeueReusableAnnotationViewWithIdentifier:@"PinAnnotationView"];
if (!annotationView) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"PinAnnotationView"];
annotationView.draggable = YES;
}
[self.locationManager stopUpdatingLocation];
return annotationView;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState
{
if(newState == MKAnnotationViewDragStateStarting) {
CLLocationCoordinate2D droppedFrom = annotationView.annotation.coordinate;
NSLog(@"dropped from %f, %f", droppedFrom.latitude , droppedFrom.longitude);
// annotationView.dragState = MKAnnotationViewDragStateDragging;
}
else if (newState == MKAnnotationViewDragStateEnding)
{
CLLocationCoordinate2D droppedAt = annotationView.annotation.coordinate;
NSLog(@"dropped at %f,%f", droppedAt.latitude, droppedAt.longitude);
annotationView.dragState = MKAnnotationViewDragStateNone;
}
else if (newState == MKAnnotationViewDragStateCanceling) {
// custom code when drag canceled...
// tell the annotation view that the drag is done
[annotationView setDragState:MKAnnotationViewDragStateNone animated:YES];
}
}
- (void)viewWillAppear:(BOOL)animated
{
[self.mapView setShowsUserLocation:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
What am i missing?
Thanks in advance.