【发布时间】:2020-11-01 23:55:18
【问题描述】:
我真的是 swift 新手,我想弄清楚为什么我在运行这个程序时得到一个 nil 值。我尝试添加func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [CLLocation]!),但这似乎不起作用。任何帮助将不胜感激。谢谢
这里是代码(PS:这是变量locManager的值:var locManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
tableView.backgroundColor = UIColor.systemGreen
tableView.estimatedRowHeight = 100
tableView.rowHeight = UITableView.automaticDimension
locManager.requestWhenInUseAuthorization()
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [CLLocation]!) {
let locationZoom = locations.last as! CLLocation
}
if CLLocationManager.authorizationStatus() == .authorizedWhenInUse || CLLocationManager.authorizationStatus() == .authorizedAlways
{
currentLocation = locManager.location
//getting locations
let longa = currentLocation.coordinate.longitude ***<- (Error occurring at this line)***
let latta = currentLocation.coordinate.latitude
nearbyLocations1(latitude: latta, longitude: longa) { (longitude, latitude, name, vicinity) in
print("name 1 is ", name)
}
nearbyLocations2(latitude: latta, longitude: longa) { (longitude, latitude, name, vicinity) in
print("name 2 is ", name)
}
}
}
【问题讨论】:
标签: ios swift xcode core-location cllocationmanager