我有我的视图控制器上的这段代码,但这不工作: import UIKit import CoreLocation class ViewController: UIViewController, CLLocationManagerDelegate { var location: CLLocationManager! override func viewDidLoad() { super.viewDidLoad() location=CLLocationManager() location.delegate = self location.desiredAccuracy=kCLLocationAccuracyBest location.startUpdatingLocation() } func locationManager(location:CLLocationManager, didUpdateLocations locations:AnyObject[]) { println("locations = \(locations)") label1.text = "success" } 我有我阅读其他职位的权限。 但我从来没有获得,没有println .. 谢谢!!
更新:从iOS 5和Xcode 4.1开始,现在可以在模拟器中testing位置,甚至定义路线。 有关更多详细信息,请参阅http://developer.apple.com 。 遗留问题 有没有在iPhone模拟器上testingCoreLocation? 我所需要的是能够自己设置位置,并使CoreLocation返回它。
我想获得当前的位置,但是我得到一个错误。 这是我的视图控制器的一个片段。 – (void)viewDidLoad { self.locationManager = [[CLLocationManager alloc] init]; [locationManager setDelegate:self]; [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters]; [locationManager startUpdatingLocation]; } – (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations { // I would get the latest location here // but this method never gets called } – (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { NSLog(@"didFailWithError: %@", error); } 我期待的委托方法locationManager:didUpdateLocations:得到调用,而是,只有locationManager:didFailWithError:被调用,并打印这个: didFailWithError: Error Domain=kCLErrorDomain Code=0 […]
在2014年初,苹果公司已经将iOS 7.0更新到7.1,以便即使应用程序在前台而不是在后台处于活动状态时也允许进行位置更新。 我们怎么做? 我已经阅读了一些文章,如苹果的iOS 7.1将修复一个地理定位错误 。 但是苹果公司并没有提供相关的通讯,也没有提供任何关于如何获取位置更新的示例代码,即使应用程序被终止/终止/挂起。 我已阅读iOS 7.1发行说明 。 我也找不到与此相关的任何内容。 那么,即使应用程序被暂停,我们如何才能真正获得iOS 7和8的位置更新?