1

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.

rome 웃
  • 1,821
  • 3
  • 15
  • 33
  • 1
    Are you trying this on the simulator? if so read here http://stackoverflow.com/questions/1409141/location-manager-error-kclerrordomain-error-0 – tmpz Jan 13 '16 at 11:09
  • 1
    Try it on the device. The iMac has no GPS chip inside.The simulator can be set to simulate GPS locatiobns, – AlexWien Jan 13 '16 at 16:03
  • I use this on my device and it just work with internet. – rome 웃 Jan 14 '16 at 03:39
  • :) I had fix it, because my app built in Ipad Air, I tested again with iphone 5 and it work. Thanks. – rome 웃 Jan 14 '16 at 04:03

0 Answers0