4

Ok so I have a map loaded with pins from a remote JSON feed which is loaded into the app. This all works fine.

Now from initial experimenting regionDidChangeAnimated gets called multiple times and so I moved my post request to a method that uses a drag map gesture recogniser which then performs a post request to get data from a JSON feed and reload my map pins after removing them. This also works perfectly.

Now the only issue I have left is if I select an annotation that is close to the edge of the screen the map moves slightly to accommodate the display of the annotation callout. The problem is regionDidChangeAnimated gets called when this happens however my post request doesn't as I call it using the gesture recogniser and so the map was not moved by user intervention but the OS. I don't want to move my Post request to the regionDidChangeAnimated as this gets called multiple times but I would like to know if there is a way to do a test if user caused map to move or it did it its-self to accommodate the callout as explained above. The regionDidChangeAnimated from the research I have looked at may get called more times than necessary so some guidance would be good on how to prevent that or detect user interaction vs OS moving the map.

Alex McPherson
  • 3,185
  • 3
  • 30
  • 41
  • I am such a plank sometimes writing problems can help. I simply removed the regionDidChangeAnimated as I have no need for it and the code that was present there I moved to my gesture which was to removeAnnotations before re-adding them doh! – Alex McPherson Jan 22 '13 at 18:07

2 Answers2

2

I have a similar problem: I want do distinguish if the displayed part of a map has been changed by program or by user interaction. Apparently, MKMapView objects do not tell me so, i.e. regionDidChangeAnimated is called in both cases without an indication why.
But since MKMapView is a subclass of UIView, and this one of UIResponder, one can implement the methods touchesBegan:withEvent: and touchesEnded:withEvent: to find out, if the map has been touched during the change of the displayed region.
If so, one can assume that the change in the displayed region was caused by user interaction. Of course you can be more specific if you investigate the set of touches and the event type of these methods more precisely.

Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116
0

I am such a plank sometimes writing problems can help. I simply removed the regionDidChangeAnimated as I have no need for it and the code that was present there I moved to my gesture which was to removeAnnotations before re-adding them doh!

Alex McPherson
  • 3,185
  • 3
  • 30
  • 41