【问题标题】:Why can I access iPhone's location without "import CoreLocation"?为什么不用“import CoreLocation”就可以访问 iPhone 的位置?
【发布时间】:2019-06-24 17:38:03
【问题描述】:

我可以使用以下代码访问设备的位置。我正在使用 MapKit 而不是 CoreLocation。我以为这个实例CLLocationManager() 和方法requestAlwaysAuthorization() 只能通过CoreLocation 框架使用?

import UIKit
import MapKit

class ViewController: UIViewController, CLLocationManagerDelegate {

    var locationManager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

        locationManager.delegate = self

        self.locationManager.requestAlwaysAuthorization()

        locationManager.startUpdatingLocation()

    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        for currentlocation in locations{
            print("\(index): \(currentlocation)")
        }
    }

}

【问题讨论】:

    标签: swift mapkit core-location


    【解决方案1】:

    MapKit 导入 CoreLocation,因此您不需要这样做。就像您不需要导入 Foundation 一样,因为您可以从 UIKit 获得它。

    【讨论】:

      猜你喜欢
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 2015-10-28
      • 1970-01-01
      • 2019-01-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多