Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

walty

macrumors member
Original poster
Jul 15, 2008
33
0
Hi,

When I try to get current location (single spot only, not continuous), I found that a single call of following only return (0,0) coordinate. I have tried to use a "for" loop with some "sleep()" inside to get the location, but all failed.

Code:
	[locationManager startUpdatingLocation];
	[locationManager stopUpdatingLocation];
	[locationManager startUpdatingLocation];

But call of same code in the succeeding events get the current location correctly.

It seems to be that the GPS location collection is available only when triggered in more than one event, which is quite weired..

But according to SDK,
Calling stopUpdatingLocation in between, however, does cause a new initial event to be sent the next time you call this method.

Any advice for this please? Thanks a lot.
 

firewood

macrumors G3
Jul 29, 2003
8,141
1,384
Silicon Valley
If you ask for a location between measurements, it will give you a previous measurement. They're time stamped so that you can ignore any really old ones. Then wait for the next measurement with a more recent time stamp.
 

walty

macrumors member
Original poster
Jul 15, 2008
33
0
But according to SDK, calling stop could actually force the collection of current GPS data :confused:

And the problem is, I don't want the "GPS Location Prompt" to be triggered until the user really need it. So I don't want to call the location start at the begin of program. Or maybe this is inevitable actually?

Thanks.
 

firewood

macrumors G3
Jul 29, 2003
8,141
1,384
Silicon Valley
The GPS radio takes some amount time to find its location (my old dedicated handheld GPS would take 3 or 4 minutes to figure out which satellites to look at). The AGPS is a little faster, but nowhere near instant. If you don't start it until you need it, it will be too late, and you may end up with an old stale leftover location.


.
 

xnakx

macrumors newbie
Oct 5, 2008
17
0
you got it right.
CoreLocation will always first return the last location it got.
best to ignore the first and wait for other updates.
in each callback from CLocationManager I ++ and int and wait for the second or third one.
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
But according to SDK, calling stop could actually force the collection of current GPS data :confused:

It returns the last known location, which can be quite different than current position. Calling start and then stop immediately doesn't give the CLLocationManager enough time to determine the current location. As firewood mentioned, the returned CLLocation has a timestamp property and depending on your accuracy needed, an older location may suffice. This is up to you, the developer, to decide. Otherwise, wait for an update event with your delegate and then call stop.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.