[英]didFailWithError: Error Domain=kCLErrorDomain Code=0 “The operation couldn’t be completed. (kCLErrorDomain error 0.)”
[英]Error Domain=kCLErrorDomain Code=2 "The operation couldn’t be completed. (kCLErrorDomain error 2.)"
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.)"。 我不确定问题是什么,有人可以看到发生了什么吗? 谢谢。
根据文档 ,这是一个网络错误,CLGeocoder需要一个有效的网络连接,以反转一个位置的地理编码。
此外,CLGeocoder将限制地理编码请求,如果超过请求率,则返回相同的错误,这也在类引用中记录。
或者,您可以将lat long传递给此google api并获取与地址相关的所有字段,具体取决于json中的“类型”
也许许可被(拒绝)这么容易但让人头疼;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.