Here is the code I wrote (based on this answer) to link the user in a bounding box defined by the upper left coordinate and the lower right coordinate.
viewDidLoad mapView
mapView = [[SKMapView alloc] initWithFrame:CGRectMake( 0.0f, 0.0f, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame) )];
SKMapZoomLimits zoomLimits;
zoomLimits.mapZoomLimitMin = 15.153500;
zoomLimits.mapZoomLimitMax = 21;
mapView.settings.zoomLimits = zoomLimits;
CLLocationCoordinate2D topLeftBoundary;
topLeftBoundary.longitude = 21.174489;
topLeftBoundary.latitude = 39.777993;
CLLocationCoordinate2D botRightBoundary;
botRightBoundary.longitude = 21.191678;
botRightBoundary.latitude = 39.765834;
_boundaries = [SKBoundingBox boundingBoxWithTopLeftCoordinate:topLeftBoundary bottomRightCoordinate:botRightBoundary];
}
isInBoundingBox.
-(BOOL) isInBoundingBox: (SKCoordinateRegion)regionBox {
if (_boundaries.topLeftCoordinate.latitude < regionBox.center.latitude || _boundaries.bottomRightCoordinate.latitude > regionBox.center.latitude ||
_boundaries.topLeftCoordinate.longitude > regionBox.center.longitude || _boundaries.bottomRightCoordinate.longitude < regionBox.center.longitude)
{
return false;
}
return true;
}
didChangeToRegion :
- (void)mapView:(SKMapView*)curMapView didChangeToRegion:(SKCoordinateRegion)region{
BOOL inBoundingBox = [self isInBoundingBox:region];
if (inBoundingBox) {
_lastValidRegion = region;
} else {
[mapView setVisibleRegion:_lastValidRegion];
}
}