0
我有地图工具包视图,当应用程序加载时,它会获取用户当前位置并对其进行跟踪。然后它运行一个功能,专注于我也链接到一个按钮的用户位置,以便用户可以浏览并聚焦到他们的位置范围。当前位置跨度在地图工具包视图中变为随机数
在这个函数中,我将span设置为0.01,但是当我打印span值时它的不同。当应用程序运行和重点的第一次,纬度跨度在0.00745918279325508
打印然后,当我打它运行完全相同的功能,对焦按钮,拉特跨度在0.0102124663369167印刷及其明显缩小
为什么在我已经将它设置为0.01时执行此操作?这里是我的代码:
@IBAction func focusLocation(sender: UIButton)
{
snapLocation()
}
var locationManager: CLLocationManager!
override func viewDidLoad()
{
super.viewDidLoad()
if (CLLocationManager.locationServicesEnabled())
{
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
snapLocation()
}
}
func snapLocation()
{
let currentLocation = locationManager.location?.coordinate
let latitude:CLLocationDegrees = (currentLocation?.latitude)!
let longitude:CLLocationDegrees = (currentLocation?.longitude)!
let latDelta:CLLocationDegrees = 0.01
let lonDelta:CLLocationDegrees = 0.01
let span = MKCoordinateSpanMake(latDelta, lonDelta)
let location = CLLocationCoordinate2DMake(latitude, longitude)
let region = MKCoordinateRegionMake(location, span)
mapkitView.setRegion(region, animated: true)
}