How can I drag my annotation onto MKmap View Like Google Pin Drop And Draging: iOS

I need help. How can I drag the annotation (map output) from one point to another in MKMapview. Adding a process is good after the output of the drop-down list on the map, and I want to drag this output (annotation) and change this place just like a Google map.

Happy coding

+5
source share
3 answers

Call first to drag

- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id) annotation { pin.draggable = YES; } - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState { if (newState == MKAnnotationViewDragStateEnding) { CLLocationCoordinate2D droppedAt = annotationView.annotation.coordinate; [annotationView.annotation setCoordinate:droppedAt]; if(DEBUG_MODE){ NSLog(@"Pin dropped at %f,%f", droppedAt.latitude, droppedAt.longitude); } } } 
+7
source

The process is that you must enable output wrapping and you will get this long destination on didChangeDragState MKMapView .

Try entering a code.

 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id < MKAnnotation >)annotation { MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"ident"]; pinView.draggable = YES; pinView.animatesDrop = YES; return pinView; } - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState { if (newState == MKAnnotationViewDragStateEnding) { droppedAt = annotationView.annotation.coordinate; NSLog(@"Pin dropped at %f,%f", droppedAt.latitude, droppedAt.longitude); } } 
+2
source

To drag an annotation, set the drag and drop property of the annotation to YES.

set the annotation draggable in the viewForAnnotation delegate viewForAnnotation .

Use the didChangeDragState delegate didChangeDragState to get new annotation coordinates.

 - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState { if (newState == MKAnnotationViewDragStateStarting) { } if (newState == MKAnnotationViewDragStateEnding) //Annotation dragging ended { CLLocationCoordinate2D droppedCord = annotationView.annotation.coordinate; NSLog(@"New position %f,%f", droppedCord.latitude, droppedCord.longitude); } } 
0
source

Source: https://habr.com/ru/post/1247008/


All Articles