Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLLocationManager.location is nil

this is my locationManager init method:

func initLocationManager() {
        seenError = false
        locationFixAchieved = false
        locationManager = CLLocationManager()
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestAlwaysAuthorization()
        locationManager.startUpdatingLocation()     
}

after calling this method this line

println(self.locationManager.location)

prints nil why is that? it worked for me well at the past i just made few changes in my app and it doesn't work well now..

like image 288
Liran Revivo Avatar asked Nov 23 '14 19:11

Liran Revivo


2 Answers

1) CLLocation location documentation - The value of this property is nil if no location data has ever been retrieved.

2) You've set the delegate for CLLocationManager. Why not implement locationManager:didUpdateLocations: and print the latest retrieved location from inside?

3) Are you using a simulator or a real device? Bear in mind that if you are using a simulator you may need to enable simulate location:

Xcode locationDropdown

You can also find a Custom Location option in: - Simulator -> Debug -> Location -> Custom Location...

like image 157
Edgar Avatar answered Nov 05 '22 03:11

Edgar


As of iOS 8 requestAlwaysAuthorization is ignored if you do not provide a string for NSLocationAlwaysUsageDescription in your Info.plist.

Link to documentation

like image 28
andershqst Avatar answered Nov 05 '22 03:11

andershqst