Я новичок в swift и пытаюсь понять, почему я получаю нулевое значение при запуске этой программы. Я попытался добавить 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)
}
}
}