MKMapView zoom to users location on viewDidLoad?

前端 未结 10 1690
有刺的猬
有刺的猬 2021-01-30 16:40

I\'m trying to zoom a map into the user\'s current location once the view loads, but I\'m getting the error \"** * Terminating app due to uncaught exception \'NSInvalidA

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-30 17:21

    Swift 3 version Use this method to zoom into any coordinate.

    extension MKMapView{
        func zoomIn(coordinate: CLLocationCoordinate2D, withLevel level:CLLocationDistance = 10000){
            let camera =
                MKMapCamera(lookingAtCenter: coordinate, fromEyeCoordinate: coordinate, eyeAltitude: level)
            self.setCamera(camera, animated: true)
        }
    }
    

提交回复
热议问题