Friday, 18 October 2013

Drag and Drop pin functionality in ios Map

In ios mapkit you can make map pin draggable :
if you want to drag the pin and drop at one location and then check its lattitude longutide then you can apply this code :

first step is to change in
- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id) annotation { 
MKPinAnnotationView *pin = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"myPin"];
if (pin == nil) { 
pin = [[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"myPin"] ; } else { pin.annotation = annotation; 
 } 
pin.animatesDrop = YES; 
pin.draggable = YES; return pin;
}

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

}

1 comment:

  1. The Casino - Filmfile Europe
    From the first three games to 베픽 the most 비트 코인 토토 사이트 샤오 미 spectacular wins, The 7m스코어 벳무브 Casino is a 프랑스 리그 1 순위 must be! From the first three games to the most spectacular wins, 파워 볼 사다리 The Casino is a must

    ReplyDelete