View Full Version : SKBoundingBox and fitBounds do not produce visible region (iOS, Swift)

11.12.2015, 20:09
When I create a bounding box and pass it to fitBounds, I get a small globe in the center of the view.

override func viewDidLoad() {

mapView.delegate = self

// This code works, but I don't want a center point and zoom, I need to specify a region
// let region = SKCoordinateRegion(center: CLLocationCoordinate2DMake(40.697198, -73.883391), zoomLevel: 12)
// mapView.visibleRegion = region

let nyNW = CLLocationCoordinate2DMake(41.722259, -75.650663)
let nySE = CLLocationCoordinate2DMake(40.161297, -71.762025)
let bbox = SKBoundingBox(topLeftCoordinate: nyNW, bottomRightCoordinate: nySE)
mapView.fitBounds(bbox, withPadding: CGSize(width: 20,height: 20))

This should show a section of New York. Instead, it shows a globe that does not include the region I specified.
The region in the bounding box is not

How do I get the map so show a specified region? The specified region should fill the map view.


14.12.2015, 14:31
You'll find a solution shared on StackOverflow for this questions: http://stackoverflow.com/questions/32031325/limit-a-map-to-certain-bounds/33792213#33792213 (it's ObjC but won't be a problem to adapt it for Swift, right?)

14.12.2015, 19:02
Thanks for the reply!

I had seen that post, but was not the problem I had. It turns out that the code works fine if I put it in viewDidAppear:animated. It does not work when it is in viewDidLoad.

11.01.2016, 10:35
Thanks for letting us know.