10

I need to accurately track the centerCoordinate of an MKMapView while the user zooms/pans the map, i.e. between the regionWillChangeAnimated: and regionDidChangeAnimated: events.

I've tested the following approaches by trying to lock an MKAnnotation to the map's center. Unfortunately, none of them work well enough:

  • Using UIPanGestureRecognizer (as described here): this works quite well while the display is touched, but doesn't update while the map is animated after the touch gesture is complete. In addition, the updates lag behind the actual centerCoordinate.

  • Using UIScrollViewDelegate I subclassed MKMapView to receive the scrollViewDidScroll: event. This worked, but the event isn't triggered on every scrolling increment, leading to jerky updates.

  • Using KVO Notifications: following this pattern, I tried to observe the mapview's centerCoordinate. It works for the userLocation, but the notifications don't seem to be sent for centerCoordinate.

Any ideas on how to track centerCoordinate effectively and accurately?

KVO seemed like the best bet. Is there a trick to making it work with MKMapView's centerCoordinate property?

Community
  • 1
  • 1
carton
  • 1,020
  • 1
  • 8
  • 17

1 Answers1

0

If I correctly understand, you are trying to have something (annotation in your case) that is always in the centre of the screen, right? Not sure what this annotation is used for, but is it acceptable to place another transparent view on top of the map that acts as annotation (you can also make this view be same size as the map and have subview of it act as annotation). It'll have the same effect on the user. Than in the region did change, you can get the centerCoordinate and do whatever processing you need to do. I don't think you need to do any processing as the user pans or pinches the map... Not to mention that annotations are meant to have fixed coordinate.

goce
  • 205
  • 3
  • 6