views:

369

answers:

2

Hi all,

I have written an iPhone app that uses the iPhone's relative GPS location.

I have a button in the user interface that does reverse geolocation (pulls the street name bases on the lat and long). The only problem is that the location object as retrieved by

CLLocation *location = [[self locationManager] location];

is nil if the user taps the button too soon. I am initializing the LocationManager in viewDidLoad as I don't want to object to be created unless the user actually loads this screen. I start updating the location straight away as well... but still if the user loads the screen and taps the GPS button straight away the location is nil.

Here comes the question: do you know roughly how much time the CLLocationManager needs to retrieve the location?

Thanks

+2  A: 

It can take the phone a few seconds to retrieve this data. For usability, you may want to deactivate the button control. Fire an NSNotification once the location is found. Register your view controller to listen for this notification, which fires a selector that re-activates the button control.

Alex Reynolds
Cheers. Displaying the button once a location is available sounds like a good idea. The users will have the option to manually type the street name anyway. Thanks!
nicktmro
Keep in mind that Core Location will typically return a less accurate (or sometimes even cached) location as it zeroes in on the correct GPS location, depending on the accuracy setting you have specified.
Hunter
A: 

Acquiring a location fix is dependent on the amount of accuracy you want, and whether it's previously had some kind of location data, what the weather is like, whether you're inside/outside ... there really isn't one answer. If you go to the Maps application and click on the 'locate' button then you'll notice that in different circumstances, it will be some time after you start the resolution process.

The callbacks will tell you when there is data; you shouldn't get it by polling or assuming instant access (or worse, blocking the app until you expect to find data). It sounds like the key problem here is your button is synchronously executing the request and not being dynamic; in other words, a race condition guaranteed to fail at some point, regardless of what value of 'n' you come up with.

Change your code so that the button invokes the location acquisition in the background, and then subsequently pops up the information or fills out the form later.

AlBlue