【发布时间】: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