I want to make app can get location (latitude & longitude) with no internet, and someone tell me use CCLocationManager, here.
And I testing with my code:
var locationManager:CLLocationManager!
@IBOutlet weak var locationTextField: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
let authstate = CLLocationManager.authorizationStatus()
if(authstate == CLAuthorizationStatus.NotDetermined){
print("Not Authorised")
locationManager.requestWhenInUseAuthorization()
}
print("first")
locationTextField.text = "11"
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print("success \(locations.count)")
let location:CLLocation = locations[locations.count - 1] as CLLocation
print("aa:\(location.coordinate.latitude) \(location.coordinate.longitude)aa")
locationTextField.text = location.description
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print("Couldn't get your location with \(error.description)")
}
But it just work with internet and when I turn off wifi, my app log: Couldn't get your location with Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
Maybe I'm wrong somewhere, any helps, thanks.