2
-(void)mapView:(MKMapView *)mapView 
    annotationView:(MKAnnotationView *)view                  
    didChangeDragState:(MKAnnotationViewDragState)newState 
    fromOldState:(MKAnnotationViewDragState)oldState
4

2 に答える 2

6

あなたはこれを使用します:

- (void)mapView:(MKMapView *)mapView 
        annotationView:(MKAnnotationView *)annotationView 
        didChangeDragState:(MKAnnotationViewDragState)newState 
        fromOldState:(MKAnnotationViewDragState)oldState 
{
    if (newState == MKAnnotationViewDragStateEnding)
    {
        CLLocationCoordinate2D droppedAt = annotationView.annotation.coordinate;
        NSLog(@"dropped at %f,%f", droppedAt.latitude, droppedAt.longitude);
    }
}

MKAnnotationViewこれにより、がドロップされたときの最終的な場所の座標が得られます。

于 2013-03-04T06:53:43.150 に答える
0

ドラッグ状態を確認してから使用するannotationView.annotation.coordinate.latitudeannotationView.annotation.coordinate.latitude、新しい場所の座標を取得できます。

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState
{

    //if dragging ended
    if (newState == MKAnnotationViewDragStateNone && oldState == MKAnnotationViewDragStateEnding) {

        MKCoordinateRegion region;
        MKCoordinateSpan span;

        span.latitudeDelta = 0.00212872;
        span.longitudeDelta = 0.00212872;

        CLLocationCoordinate2D location;
        location.latitude = annotationView.annotation.coordinate.latitude;
        location.longitude = annotationView.annotation.coordinate.longitude; 
        [self getAddress:location.latitude withLong:location.longitude];

        region.span = span;
        region.center = location;

        if (addAnnotation != nil) {
            [myMap removeAnnotation:addAnnotation];
            [addAnnotation release];
            addAnnotation = nil;
        }

        addAnnotation = [[Annotation alloc] init];
        addAnnotation.coordinate = location;
        [myMap addAnnotation:addAnnotation];
        [myMap setRegion:region animated:YES];
        [myMap regionThatFits:region];
    }

}

addAnnotation は のオブジェクトですAnnotation

于 2013-03-04T06:54:55.780 に答える