Skip to content

Instantly share code, notes, and snippets.

@gotomanners
Forked from Proper-Job/gist:e11cca67e77285566d4d
Last active August 29, 2015 14:20
Show Gist options
  • Save gotomanners/dca360cc762852a7b1d5 to your computer and use it in GitHub Desktop.
Save gotomanners/dca360cc762852a7b1d5 to your computer and use it in GitHub Desktop.
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
if (!self.manuallyChangingMap) {
BOOL updateRegion = NO;
MKCoordinateRegion restrictedRegion = [self restrictedRegion];
if ((mapView.region.span.latitudeDelta > restrictedRegion.span.latitudeDelta * 4) || (mapView.region.span.longitudeDelta > restrictedRegion.span.longitudeDelta * 4) ) {
updateRegion = YES;
}
if (fabs(mapView.region.center.latitude - restrictedRegion.center.latitude) > restrictedRegion.span.latitudeDelta) {
updateRegion = YES;
}
if (fabs(mapView.region.center.longitude - restrictedRegion.center.longitude) > restrictedRegion.span.longitudeDelta) {
updateRegion = YES;
}
if (updateRegion) {
self.manuallyChangingMap = YES;
[mapView setRegion:region animated:YES];
self.manuallyChangingMap = NO;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment