GPS Location takes a few seconds to be retrieved

不羁的心 提交于 2019-12-10 12:04:51

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/1385088/gps-location-takes-a-few-seconds-to-be-retrieved

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!