2016-04-13 9 views

Antwort

7

erste Stift erlauben zu ziehen

- (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); 
     } 
    } 

} 
+0

Thx Bruder Tysm ... Sie schaukelte ..... (Thumps +1) @Bhavin Ramani –

+0

@RahulSharma immer willkommen ... –

2

Der Prozess ist Sie Stift ermöglichen, müssen dragable, und Sie werden das Ziel des lat lange auf didChangeDragState von MKMapView bekommen.

Versuchen Sie den folgenden 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); 
    } 
} 
0

Um eine Anmerkung zu ziehen, legen Sie die Eigenschaft draggable der Anmerkung zu YES.

Legen Sie die Beschriftung der Anmerkung in der Delivery-Methode viewForAnnotation fest.

Verwenden Sie die Delegate-Methode didChangeDragState Methode, um neue Koordinaten Ihrer Annotation zu erhalten.

- (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); 
    } 
}