Rahul Sharma Rahul Sharma - 3 years ago 120
iOS Question

How Can I Drag My Annotation On MKmap View Like Google Pin Drop And Draging:iOS

I need some help. How can i drag annotation (map pin) from one point to another in MKMapview.
Adding process is all good after pin drop-down on the map and i want to drag that pin (annotation) and change that place just like Google map.

Happy Coding

Answer Source

First allow pin to drag

- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id) annotation 
    pin.draggable = YES; 

- (void)mapView:(MKMapView *)mapView
 annotationView:(MKAnnotationView *)annotationView
    if (newState == MKAnnotationViewDragStateEnding)
        CLLocationCoordinate2D droppedAt = annotationView.annotation.coordinate;
        [annotationView.annotation setCoordinate:droppedAt];
        NSLog(@"Pin dropped at %f,%f", droppedAt.latitude, droppedAt.longitude);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download