从Screen Swift MapKit中心获取位置

Fel*_*var 5 location screen center mapkit swift

我是Swift Programming的新手,我正在尝试构建一个应用程序,我可以使用MapKit和Swift 2获取视图中心的坐标.

我已经可以获得当前位置,但是如果我在地图上移动,我需要将位置设置为新点,这将是屏幕的中心.

你可以帮帮我吗?

问候,

ado*_*srs 13

您可以使用regionDidChangeAnimated委托方法并调用mapView.centerCoordinate.它将如下所示:

 func mapView(mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
        var center = mapView.centerCoordinate
   }
Run Code Online (Sandbox Code Playgroud)

还要确保您的班级正在扩展MKMapViewDelegate并且您正在调用 self.mapView.delegate = self您的viewDidLoad()函数.