Search code examples
iosswiftcllocation

CLLocation 'coordinate' is unavailable


I have an issue using getting lat and long from a CLLocation object.

The weird thing is, up until yesterday I was able to retrieve the lat and long by doing:

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

    var location: AnyObject? = locations.last

    if let location: AnyObject = location {
        //The println illustrates how I would retrieve the lat and long, i.e. by calling
        //location.coordinate.latitude.

        println(location.coordinate.latitude)

        locationDelegate?.updateLabels(location)
        self.locationsArray.append(location)
    }
}

This has now stopped working and it throws me the following compiler error:

enter image description here

If i remove the .coordinate call and call .latitude directly on the location object, it just returns nil. I'm a bit lost as to whats going on here...

if I println(location) i get the following output:

<+56.92239472,+1.47020887> +/- 5.00m (speed -1.00 mps / course -1.00) @ 10/11/14, 2:37:59 PM British Summer Time

Can anybody help me understand whats going on and how to retrieve the lat and long again?


Solution

  • Using the func locationManager(manager: CLLocationManager!, didUpdateToLocation newLocation: CLLocation!, fromLocation oldLocation: CLLocation!)instead of the above delegate method and then calling newLocation.coordinate.latitude seems to work.