开发者

Need a delay to wait for GPS

开发者 https://www.devze.com 2023-03-10 10:47 出处:网络
Using the iPhone and objective C, is there a way to stall or perform a timing loop to allow for the GPS to catch up and return a valid set of coordinates?

Using the iPhone and objective C, is there a way to stall or perform a timing loop to allow for the GPS to catch up and return a valid set of coordinates?

Currently, the application runs too quickly and the GPS cannot supply the coordina开发者_运维技巧tes fast enough...


Since you said you're on iPhone, you're using CLLocationManager. Just set a delegate on the manager and wait for the locationManager:didUpdateToLocation:fromLocation: message to know when the GPS data is ready.


Assuming your GPS polling is running in a different thread to the User Interface, you can call the static NSThread functions sleepForTimeInterval or sleepUntilDate from the thread that is waiting for the GPS data.


If your mobile application is using GPS, your application should be prepared for location updates, even if your application doesn't track movements.. A common case would be where the user put your application in background and activate it later on a completely different location.

On iOS, create an implementation of CLLocationManagerDelegate like Anomie wrote. And use the timestamp of the update to evaluate the freshness of the location.

Don't sleep & poll like other people suggested.


Either block to wait for data or don't update anything if no data received. There is of course usleep(), but without showing code and specifically how your loop is executed and by what mechanism (threaded or not) we can only answer in general terms.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号