2

Is there a way to determine if a MKMapView drag and zoom stops?

Right now I've added an UIPanGestureRecognizer for dragging MKMapView but I'll receive gestureRecognizer.state == UIGestureRecognizerStateEnded immediately when the user lift his finger even though the map is scrolling. What I try to figure out is how to prevent loading server data for my map annotations when the map is still moving and/or the user touches the map one's again to drag the map again? The data load mechanism should be only called when the map stops moving and zooming and is standing still for some predefined time.

This is what I've implement so far:

- (void)viewDidLoad {
...
  UIPanGestureRecognizer* panRec = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(didDragMap:)];
  [panRec setDelegate:self];
  [panRec setDelaysTouchesBegan:YES];
  [panRec setDelaysTouchesEnded:YES];
  [panRec setCancelsTouchesInView:YES];
  [self.mapView addGestureRecognizer:panRec];
}

And the selector method didDragMap:

- (void)didDragMap:(UIGestureRecognizer*)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
    _searchBar.text = @"";
    _filtered = NO;
    _crosshair.hidden = NO;
    [self removeAllAnnotationExceptOfOriginalLocation];
}
else if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
    [self performSelector:@selector(delayAddressResolving:) withObject:nil afterDelay:1.0];
}

}

The selector method delayAddressResolving: is loading the needed data from server to display the information for my annotations.

All notes are welcome!

Darshan Kunjadiya
  • 3,323
  • 1
  • 29
  • 31
DoK
  • 851
  • 3
  • 15
  • 31
  • did you find some Solution for this? I am having the same prob. – Jasmeet Feb 24 '15 at 07:31
  • In my case I executed an Independent Thread, which was checking the Lat Long of a Pin I placed in the Middle. if there was change in the current and previous values API will be called. Please share your solution too. – Jasmeet Feb 24 '15 at 07:33

2 Answers2

0

Use the following MKMapViewDelegate methods:

    - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
    - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated

These methods are called every time when map region is changing.

iOS Dev
  • 4,143
  • 5
  • 30
  • 58
  • 1
    These delegate methods will be called many times to report map position updates as written in the documentation: [Apple-Documentation](https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/occ/intfm/MKMapViewDelegate/mapView:regionDidChangeAnimated:) This won't help to solve the problem to detect the time, when zooming or scrolling of the map view did finished. I need to find out the time when zooming or scrolling did finished to fire my method for downloading server data for my annotations. – DoK Jun 24 '14 at 12:33
  • Also, the delegate methods are not called solely in response to user interaction. Animating a layout change that affects the MapView will also result in these methods being called, for example. – stephent Jan 24 '15 at 22:29
0

determine if MKMapView was dragged/moved http://developer.apple.com/library/ios/#samplecode/Breadcrumb/Listings/Classes_BreadcrumbViewController_m.html. It may help you

Community
  • 1
  • 1
Iphonenew
  • 299
  • 2
  • 11
  • There is no solution for the described problem in the implementation example you posted, see [Classes_BreadcrumbViewController](https://developer.apple.com/library/ios/samplecode/Breadcrumb/Listings/Classes_BreadcrumbViewController_m.html) – DoK Jun 24 '14 at 12:40