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 回答