2016-04-13 88 views

cevap

7

İlk pim,

- (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 Kardeş Tysm ... Sen sarsan ..... (gümbürtü Yukarı 1) @Bhavin Ramani –

+0

@RahulSharma Daima hoşgeldin ... –

2

işlemi pim dragable izin vermeniz gerekir, ve MKMapView ait didChangeDragState o hedef en lat uzun alacak.

Kodu aşağıdan deneyin.

- (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

bir şerh sürükleyin sürüklemek YES ek açıklamanın sürüklenebilir özelliğini ayarlamak için izin verir.

ek açıklamanın viewForAnnotation temsilci yönteminde sürüklenmesini ayarlayın.

Ek açıklamanızın yeni koordinatlarını almak için temsilci yöntemini didChangeDragState yöntemini kullanın.

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