0

I saw simple code for calculating a grid of tile bounds needed for a given MKMapRect but I can't find it now. IIRC it was a function built-in to MapKit.

Given a MKMapRect like mapview.visibleMapRect and zoom level, how can I calculate an array of tile paths that will be used for the given rect?

import MapKit

class ViewController: UIViewController {

    @IBOutlet weak var mapview: MKMapView!

    override func viewDidLoad() {
        super.viewDidLoad()
        mapview.delegate = self

        let location = CLLocationCoordinate2D(latitude: 44.0, longitude: -120.0)
        let span = MKCoordinateSpanMake(1.0, 1.0)
        let region = MKCoordinateRegion(center: location, span: span)
        mapview.setRegion(region, animated: true)

        let rect = mapview.visibleMapRect
    
        let requiredTiles = ?
    }
}
Jeshua Lacock
  • 5,730
  • 1
  • 28
  • 58

0 Answers0