You have to register for KVO notifications of userLocation.location
property of MKMapView
.
To do this, put this code in viewDidLoad:
of your ViewController or anywhere in the place where your map view is initialized.
[self.mapView.userLocation addObserver:self
forKeyPath:@"location"
options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
context:NULL];
Then implement this method to receive KVO notifications
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
if ([self.mapView showsUserLocation]) {
[self moveOrZoomOrAnythingElse];
// and of course you can use here old and new location values
}
}
This code works fine for me.
BTW, self
is my ViewController in this context.