使用Core Location获取坐标并计算100米圆翼
Using Core Location to get coordinates and calcule who is 100 meters round wing
目前在我的应用程序中,我正在获取用户坐标。我需要保持此坐标始终更新,因此我将位置代码放在应用程序委托中的 didFinishLaunchingWithOptions 中。代码是:
let location = CLLocationManager()
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
location.delegate = self
location.desiredAccuracy = kCLLocationAccuracyBest
location.requestAlwaysAuthorization()
location.requestWhenInUseAuthorization()
return true
然后,在同一个 AppDelegate.swift 中,我实现了委托方法来捕获每个位置更新,如下所示:
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print(locations)
}
问题是我总是收到零值。
值得一提的是,我在模拟器上 运行 应用程序,但在调试菜单中我模拟骑自行车甚至 Apple 位置。
我错过了什么?
当然我用 NSLocationAlwaysUsageDescription 和 NSLocationWhenInUseUsageDescription
编辑了 plist
manager.startUpdatingLocation()
目前在我的应用程序中,我正在获取用户坐标。我需要保持此坐标始终更新,因此我将位置代码放在应用程序委托中的 didFinishLaunchingWithOptions 中。代码是:
let location = CLLocationManager()
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
location.delegate = self
location.desiredAccuracy = kCLLocationAccuracyBest
location.requestAlwaysAuthorization()
location.requestWhenInUseAuthorization()
return true
然后,在同一个 AppDelegate.swift 中,我实现了委托方法来捕获每个位置更新,如下所示:
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print(locations)
}
问题是我总是收到零值。
值得一提的是,我在模拟器上 运行 应用程序,但在调试菜单中我模拟骑自行车甚至 Apple 位置。
我错过了什么?
当然我用 NSLocationAlwaysUsageDescription 和 NSLocationWhenInUseUsageDescription
编辑了 plistmanager.startUpdatingLocation()