问:所以我想获取iPhone(模拟器)的坐标,但是每次都会给我一个错误。有人可以告诉我很好的代码(Swift 2.0,Xcode 7.0.1)预先感谢。
答:import UIKit
import CoreLocation
类ViewController :UIViewController ,CLLocationManagerDelegate {让locationManager = CLLocationManager ()覆盖func viewDidLoad (){ super 。viewDidLoad ()locationManager 。委托=自我locationManager 。neededAccuracy = kCLLocationAccuracyBest locationManager 。requestWhenInUseAuthorization ()locationManager 。
startUpdatingLocation ()
}覆盖FUNC didReceiveMemoryWarning (){超级。didReceiveMemoryWarning ()//处理任何可以重新创建的资源。} func locationManager (管理器:CLLocationManager ,didUpdateLocations位置:[ CLLocation ]){ } func locationManager (管理器:CLLocationManager ,didFailWithError错误:NSError ){
打印(“错误:” + 错误。localizedDescription )
} }