When you say that you've tried stopping/starting the CLLocationManager
object, are you saying that the call-back you get in your delegate gives you a 0,0 coordinate, or are you trying to access the location directly using the location
property in CLLocationManager
?
I work on a location based app and one thing I can tell you is that you cannot count of directly getting the location of a CLLocationManager
object. The only reliable way to get location information is to rely on the callback of the CLLocationManager
class by implementing
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
The way I handle CLLocationManager
in my app (now I'm not saying this is optimal or ideal for your use case but it does allow us to provide a solid location-based experience to the user on app launch/resume)
- Wrap the
CLLocationManager
into a location management class (usually using a singleton) - I think this can be a subclass of CLLocationManager
but in my case it's just a subclass of NSObject
with a CLLocationManager
object as a property
- Store the last known valid location in this singleton, and then write it to disk (NSUserDefaults or another location - need to re-check if you're allowed to store user location in
NSUserDefaults
but we've done it in our app and doesn't seem to affect the approval process)
- Re-implement a way to get the current location in your custom class - basically check if
CLLocationManager
is returning 0,0 and if it is, return your cached position instead
- Not strictly necessary but if you have multiple views/pages that need to use the location, implementing the observer model works well (since your singleton is now
CLLocationManager
's delegate, you need to have a way to pass this information on to your view controllers).
With the above, on my map page (or wherever I'm displaying user location) - I basically update the map with the cached location once (in viewDidLoad
) and then I allow one update to the map through the delegate-callback. Once that call-back is received, I then set showsUserLocation
to YES
(if the call-back isn't called, then you don't have a valid location yet and so setting showsUserLocation
at that point doesn't do anything).
I hope this helps and feel free to let me know if you have any further questions!