2013-03-04 42 views
2
-(void)mapView:(MKMapView *)mapView 
    annotationView:(MKAnnotationView *)view     
    didChangeDragState:(MKAnnotationViewDragState)newState 
    fromOldState:(MKAnnotationViewDragState)oldState 
+0

接受按鈕在哪裏? – Gaurav 2013-03-05 11:44:14

回答

6

您的使用這種得到新的位置。

+0

現在感謝它的工作 – Gaurav 2013-03-06 13:57:28

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的對象。