从Screen Swift MapKit的中心获取位置 [英] Get Location From Center of Screen Swift MapKit

查看:170
本文介绍了从Screen Swift MapKit的中心获取位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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.

您能帮我吗?.

此致

推荐答案

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

You can use the regionDidChangeAnimated delegate method and call mapView.centerCoordinate. It will look like the following:

 func mapView(mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
        var center = mapView.centerCoordinate
   }

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

Also make sure that your Class is extending MKMapViewDelegate and you are calling self.mapView.delegate = self in your viewDidLoad() function.

这篇关于从Screen Swift MapKit的中心获取位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆