使用核心位置获取坐标并计算谁是100米圆翼

时间:2016-07-05 13:19:04

标签: swift core-location appdelegate

目前在我的应用程序中我正在获取用户坐标。我需要保持这个坐标始终更新,所以我将位置代码放在了didFinishLaunchingWithOptions的app delegate中。代码是:

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

1 个答案:

答案 0 :(得分:0)

manager.startUpdatingLocation()