annotationView didChangeDragState being fired multiple times

Posted by RodH257 on Stack Overflow See other posts from Stack Overflow or by RodH257
Published on 2011-06-14T15:16:01Z Indexed on 2012/09/04 9:38 UTC
Read the original article Hit count: 657

Filed under:
|
|
|

I've got a draggable annotation in IOS4 mapkit, and I'm trying to call an event when the annotation is dragged to a new position.

my code currently looks like:

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

        //update the annotation
        //see if its an information annotation
        if ([annotationView.annotation isKindOfClass:[InfoAnnotation class]]) {
            NSLog(@"Info annotation updating..");
            InfoAnnotation* userAnnotation = ((InfoAnnotation *)annotationView.annotation);
            [userAnnotation updateLocationWithServerForConvoy: self.title];
        }

    }
}

the code simply logs the update and then tells the annotation to send its update to my server, which is a custom method.

This method seems to be getting fired multiple times, see the log here:

2011-06-15 01:12:39.347 Convoy[1699:207] dropped at 37.340206,-122.027550
2011-06-15 01:12:39.347 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:39.658 Convoy[1699:207] dropped at 37.340206,-122.027550
2011-06-15 01:12:39.659 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:39.957 Convoy[1699:207] dropped at 37.340206,-122.027550
2011-06-15 01:12:39.958 Convoy[1699:207] Info annotation updating..


2011-06-15 01:12:43.415 Convoy[1699:207] dropped at 37.339251,-122.026691
2011-06-15 01:12:43.416 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:43.713 Convoy[1699:207] dropped at 37.339251,-122.026691
2011-06-15 01:12:43.713 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:44.006 Convoy[1699:207] dropped at 37.339251,-122.026691
2011-06-15 01:12:44.006 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:44.297 Convoy[1699:207] dropped at 37.339251,-122.026691
2011-06-15 01:12:44.297 Convoy[1699:207] Info annotation updating..


2011-06-15 01:12:54.825 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:54.825 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:55.150 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:55.150 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:55.475 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:55.476 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:55.771 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:55.772 Convoy[1699:207] Info annotation updating..
2011-06-15 01:12:56.070 Convoy[1699:207] dropped at 37.337135,-122.025833
2011-06-15 01:12:56.070 Convoy[1699:207] Info annotation updating..

Each time I drag it (ie in the gaps) it seems to add 1 to the amount of times it's called. Can anyone give me any idea what may be causing this?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about ios