【发布时间】:2019-12-29 05:53:07
【问题描述】:
我想得到longitude和latitude,我在控制器中添加CLLocationManagerDelegate。
这是我的代码
let locationManager = CLLocationManager()
func getWeatherInformation(){
var currentLocation: CLLocation!
locationManager.requestWhenInUseAuthorization()
if( CLLocationManager.authorizationStatus() == .authorizedWhenInUse ||
CLLocationManager.authorizationStatus() == .authorizedAlways){
currentLocation = locationManager.location
}
let longitude = "\(currentLocation.coordinate.longitude)"
let latitude = "\(currentLocation.coordinate.latitude)"
}
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
getWeatherInformation()
}
}
我还在info.plist中添加了位置项,请看截图
问题是longitude 和latitude,在运行应用程序并崩溃后发现为零。
问题出在哪里?
非常感谢
【问题讨论】: