2017-09-18 33 views
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) 
    } 

回答

0

根據蘋果文檔:

當設置一個新的區域,在地圖上可以調整該地區 參數的值,使其適合在地圖的可視區域恰恰。這是 是正常的,並且確保區域屬性 中的值總是反映地圖的可見部分。但是,它的意思是 ,如果您在調用此 方法後立即獲得該屬性的值,則返回的值可能與您設置的值不匹配。

因此,當您應用span時,它會創建最適合您請求的區域。它不會和你所要求的完全一樣。