【发布时间】:2019-03-28 07:32:58
【问题描述】:
位置未打印到控制台。我之前有过这个确切的代码,但自从更新到 Xcode 10 后,它并没有将用户当前位置打印到控制台中。
var locationManager: CLLocationManager!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
determineMyCurrentLocation()
}
func determineMyCurrentLocation() {
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
if CLLocationManager.locationServicesEnabled() {
locationManager.startUpdatingLocation()
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let userLocation:CLLocation = locations[0] as CLLocation
print("user latitude = \(userLocation.coordinate.latitude)")
print("user longitude = \(userLocation.coordinate.longitude)")
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error)
{
print("Error \(error)")
}
【问题讨论】:
-
在上面的代码中?
-
欢迎来到 Stack Overflow,这个问题似乎已经回答了here
-
这个我已经试过了,位置还没更新
-
什么都没有
-
@Gary Host 最好在真实设备中测试定位服务而不是模拟器。如果使用模拟器,您可以通过以下方式模拟位置:Debug > Location > Custom Location..
标签: swift core-location xcode10