gpt4 book ai didi

ios - 错误域=kCLErrorDomain 代码=2 "The operation couldn’ t 完成。 (kCLErrorDomain 错误 2。)”

转载 作者:搜寻专家 更新时间:2023-10-31 22:08:27 25 4
gpt4 key购买 nike

import UIKit
import CoreLocation

class ViewController: UIViewController, CLLocationManagerDelegate {

@IBOutlet var latLabel: UILabel!
@IBOutlet var longLabel: UILabel!

@IBOutlet var courseLabel: UILabel!
@IBOutlet var speedLabel: UILabel!
@IBOutlet var altLabel: UILabel!
@IBOutlet var addressLabel: UILabel!

var manager:CLLocationManager!
var userLocation:CLLocation = CLLocation()

override func viewDidLoad() {
super.viewDidLoad()

manager = CLLocationManager()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestWhenInUseAuthorization()
manager.distanceFilter = 50
manager.startUpdatingLocation()


}

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {

userLocation = locations[0] as CLLocation
println(userLocation.coordinate.latitude)

var latitude:CLLocationDegrees = userLocation.coordinate.latitude
latLabel.text = "\(latitude)"
var longitude:CLLocationDegrees = userLocation.coordinate.longitude
longLabel.text = "\(longitude)"

var course:CLLocationDirection = userLocation.course
courseLabel.text = "\(course)"

var speed:CLLocationSpeed = userLocation.speed
speedLabel.text = "\(speed)"

var altitude:CLLocationAccuracy = userLocation.altitude
altLabel.text = "\(altitude)"


CLGeocoder().reverseGeocodeLocation(userLocation, completionHandler: { (placemarks, error) -> Void in

if (error != nil) {

println(error)

} else {
if let p = CLPlacemark(placemark: placemarks?[0] as CLPlacemark) {
println(p)
}
}

})



//println("Location = \(locations)")
println(locations)
}


}

当我尝试获取用户最近的地址时,我不断收到错误 Error Domain=kCLErrorDomain Code=2 "The operation couldn't be completed. (kCLErrorDomain error 2.)"。我不确定问题是什么,任何人都可以看到发生了什么吗?谢谢。

最佳答案

这是一个网络错误,根据 the docs,CLGeocoder 需要有效的网络连接才能对位置进行反向地理编码。 .

此外,CLGeocoder 将限制地理编码请求,如果您超过请求速率,将返回相同的错误,这也记录在类引用中。

关于ios - 错误域=kCLErrorDomain 代码=2 "The operation couldn’ t 完成。 (kCLErrorDomain 错误 2。)”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29087660/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com