What code does iPhone Compass use to display location coordinates even without an internet connection?

Hi,

I have made an app that will display the co-ordinates of the user location. It works fine with Wifi connectivity but fails to display anything despite waiting for 2-3 minutes, when there isn't internet connection and even when clear of obstructions. I was curious how Compass, iphone's inbuilt app could display the coordinates in a matter of seconds after calibration.






My following code, which is written in swift, finds the address based on the co-ordinates from GPS. I'm just confused why this code isn't able to display latitude and longitude in the absence of internet connectivity.






Any help is greatly appreciated. Thank you!






  import UIKit
    import CoreLocation
   
    class ViewController2: UIViewController, CLLocationManagerDelegate
   
   
   
    {
       
        @IBOutlet var locality: UILabel?
        @IBOutlet var postalCode: UILabel?
        @IBOutlet var AdministrativeArea: UILabel?
        @IBOutlet var country: UILabel?
        @IBOutlet var latitude: UILabel?
        @IBOutlet var longitude: UILabel?
       
   
        var currentLocation = CLLocation()
   
        let locationManager = CLLocationManager()
   
      
   
        override func viewDidLoad()
   
        {
   
            super.viewDidLoad()
   
          
   
            self.locationManager.delegate = self
   
           
   
            self.locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers
   
            self.locationManager.requestWhenInUseAuthorization()
   
           
   
            self.locationManager.startUpdatingLocation()
   
            currentLocation = locationManager.location
   
          
   
        }
   
      
   
        override func didReceiveMemoryWarning()
   
        {
   
            super.didReceiveMemoryWarning()
   
           
   
        }
   
      
   
        func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!)
   
        {
   
          
   
            CLGeocoder().reverseGeocodeLocation(manager.location, completionHandler: {(placemarks, error)->Void in
   
              
   
                if (error != nil)
   
                {
   
                    println("Error: " + error.localizedDescription)
   
                    return
   
                }
   
              
   
                if placemarks.count > 0
   
                {
   
                    let pm = placemarks[0] as! CLPlacemark
   
                    self.displayLocationInfo(pm)
   
                }
   
                else
   
                {
   
                    println("Error with the data.")
   
                }
   
            })
   
        }
   
     
   
      
   
        func displayLocationInfo(placemark: CLPlacemark)
   
        {
   
          
   
            /
   
            locality?.text = "\(placemark.locality)"
   
          
   
            postalCode?.text = "\(placemark.postalCode)"
   
          
   
            AdministrativeArea?.text = "\(placemark.administrativeArea)"
   
          
   
            country?.text = "\(placemark.country)"
   
          
   
            latitude?.text = "\(currentLocation.coordinate.latitude)"
   
          
   
            longitude?.text = "\(currentLocation.coordinate.longitude)"
   
          
   
        }

These three lines


            self.locationManager.requestWhenInUseAuthorization() 
            self.locationManager.startUpdatingLocation() 
            currentLocation = locationManager.location


are problematic. First, you should not call startUpdatingLocation unless you are sure you have authorization. That means you should check the authorization status, and only call it if already authorized. If not authorized, then you request authorization, and wait until your delegate's authorization status did change callback before starting location updates. Second, although the code you posted doesn't appear to use it anyway, the location manager will not have a valid location until some later time when didUpdateLocations is called. So that currentLocation assignment will not be assigning a valid location.

What code does iPhone Compass use to display location coordinates even without an internet connection?
 
 
Q