MKMapView: Zoom to default “country level”

限于喜欢 提交于 2019-12-04 12:05:46

To do that, it needs two types of information. The center coordinates for the selected country and the correct value to set for region.span on the map. It likely has access to that data from the Apple Maps database. I am not aware of that being made public to us. But there are other geocoding databases out there on the internet if you search around that might give you those two values.

If you find one that has what you want, then you set it on the map using:

myMKMapView.region.center = // Center coordinates of country
myMKMapView.region.span = // A value large enough to enclose the country.

You could just simply save default area on viewDidAppear and then use it when needed :}

class MyController: UIViewController {
    @IBOutlet weak var mapView: MKMapView!
    var defaultRegion: MKCoordinateRegion?

    override func viewDidAppear(animated: Bool) {
        defaultRegion = mapView.region
    }

    func showDefaultMapArea() {
        if let region = defaultRegion {
            mapView.setRegion(region, animated: true)
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!