Results 1 to 4 of 4

Thread: SKBoundingBox and fitBounds do not produce visible region (iOS, Swift)

  1. #1
    Etablierter skobbler
    Join Date
    26.10.2015
    Posts
    36

    SKBoundingBox and fitBounds do not produce visible region (iOS, Swift)

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

    Code:
    override func viewDidLoad() {
    	super.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.
    fitBounds.jpg
    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.

    Thanks!

  2. #2
    Oberskobbler
    Join Date
    22.07.2014
    Posts
    399
    You'll find a solution shared on StackOverflow for this questions: http://stackoverflow.com/questions/3...92213#33792213 (it's ObjC but won't be a problem to adapt it for Swift, right?)

  3. #3
    Etablierter skobbler
    Join Date
    26.10.2015
    Posts
    36
    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.
    Last edited by jimt2000; 22.12.2015 at 22:12.

  4. #4
    Oberskobbler
    Join Date
    22.07.2014
    Posts
    399
    Thanks for letting us know.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •