I'm new on Swift Programming, and I'm trying to build an app that I can get the coordinates of the center of the view with MapKit and Swift 2.
我是Swift Programming的新手,我正在尝试构建一个应用程序,我可以使用MapKit和Swift 2获取视图中心的坐标。
I already can get the current location, but I need if I move on the map, the location set to the new point which will be the center of the screen.
我已经可以获得当前位置,但是如果我在地图上移动,我需要将位置设置为新点,这将是屏幕的中心。
Can you help me with this please?.
你可以帮帮我吗?
Regards,
1 个解决方案
#1
9
You can use the regionDidChangeAnimated delegate method and call mapView.centerCoordinate. It will look like the following:
您可以使用regionDidChangeAnimated委托方法并调用mapView.centerCoordinate。它将如下所示:
func mapView(mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
var center = mapView.centerCoordinate
}
Also make sure that your Class is extending MKMapViewDelegate
and you are calling self.mapView.delegate = self
in your viewDidLoad()
function.
还要确保您的类正在扩展MKMapViewDelegate,并且您在viewDidLoad()函数中调用self.mapView.delegate = self。
#1
9
You can use the regionDidChangeAnimated delegate method and call mapView.centerCoordinate. It will look like the following:
您可以使用regionDidChangeAnimated委托方法并调用mapView.centerCoordinate。它将如下所示:
func mapView(mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
var center = mapView.centerCoordinate
}
Also make sure that your Class is extending MKMapViewDelegate
and you are calling self.mapView.delegate = self
in your viewDidLoad()
function.
还要确保您的类正在扩展MKMapViewDelegate,并且您在viewDidLoad()函数中调用self.mapView.delegate = self。