Вот код, я написал (based on this answer), чтобы связать пользователя в кадрирования, определяется сверху левой координаты и нижней правой координаты.
В моей viewDidLoad
после начала объекта MAPview как так
mapView = [[SKMapView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame))];
//Setting the zoom limit, (totally optional)
SKMapZoomLimits zoomLimits;
zoomLimits.mapZoomLimitMin = 15.153500;
zoomLimits.mapZoomLimitMax = 21;
mapView.settings.zoomLimits = zoomLimits;
//Creating our bounding box by specifying a top left point, and a bottom right
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{
//NSLog(@" @@@@@@@@ did change to ZOOM LEVEL: %f and lat: %f, long: %f",region.zoomLevel, region.center.latitude, region.center.longitude);
BOOL inBoundingBox = [self isInBoundingBox:region];
if (inBoundingBox) {
// if mapRegion is valid save it
_lastValidRegion = region;
} else {
// if mapRegion is invalid reposition the map inside the bounding box
[mapView setVisibleRegion:_lastValidRegion];
}
}