0

With IOS MapKit, how can one get callbacks during the dragging of the map itself? I know I can detect the begin and end of a drag, however I want to get callbacks during the drag. As such I'm after a stream of callbacks as the user begins to drag, then a break when they still have their finger down and have not released, then more callbacks as they keep dragging again.

Background: Want a trigger to update the centre lat/long of the current map as the user moves the map. Not sure how the rate of updates for my requirements would be controlled, however perhaps if there is a callback function I am not aware of it will be configurable?

Backup Question: If this is not possible out of the box with MKMapView then how would you best recommend I cover my requirements?

Greg
  • 34,042
  • 79
  • 253
  • 454

1 Answers1

2

You need implement MKMapViewDelegate methods for example

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

or add your panGesture to map

UIPanGestureRecognizer* panRec = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(didDragMap:)]; 
panRec.delegate = self; 
[self.mapView addGestureRecognizer:panRec];

and need implement pan delegate method

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {   
    return YES;
}
iSashok
  • 2,326
  • 13
  • 21
  • I've tried this and they only fire when you start to drag, and when you finish dragging. Not in between :( – Greg Jun 03 '16 at 05:43
  • You can add panGesture to map `UIPanGestureRecognizer* panRec = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(didDragMap:)]; panRec.delegate = self; [self.mapView addGestureRecognizer:panRec];` – iSashok Jun 03 '16 at 05:45
  • ok thanks - there's no existing delegate call then is there? If you want to update your answer with the UIPanGestureRecognizer approach I can select – Greg Jun 03 '16 at 05:46
  • had to unselect for the moment - doesn't seem to be this straight forward - I did see some notes here http://stackoverflow.com/questions/5005597/uipangesturerecognizer-on-mkmapview, and use shouldRecognizeSimultaneouslyWithGestureRecognizer but no luck yet – Greg Jun 03 '16 at 06:12
  • ok - got it - so you need (as the previous link mentioned) to add this into the mix: extension GcMapView : UIGestureRecognizerDelegate { func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool { return true } } – Greg Jun 03 '16 at 06:30
  • Yeah I agree with you – iSashok Jun 03 '16 at 06:31