views:

12002

answers:

4

Hello -

I'm looking for some feedback, blog links, etc that offer some tips and tricks for iPhone GPS development. I've read and understand the API, I have my demo app up and running, etc but I have run into some "quirks" with gps on iphone. For example, it seems that you you will receive a lot less location updates when your iphone enters "power save" mode. I've read that you can combat this by playing music in your application [not sure if this is true].

It also seems that, terms of making a reasonable pedometer, you should filter out any reading with horizontal accuracies less than 20 meters. Does this sound right?

Is there any kind of checklist out on the web for iphone gps gotchas?

Thanks in advance.

+29  A: 

I don't know of any specific list, but here are a few of things you should keep in mind:

  • You're not doing GPS lookups. You're doing Core Location lookups. Core Location might or might not be getting its information from GPS. Lots of people still use pre-3g iPhones that don't have GPS, and even on a 3g phone GPS may be unavailable in many cases (if the person is indoors, for example). In those cases the phone will attempt to triangulate based on cell phone towers, and Core Location will return the result. It'll be much less precise than GPS.
  • Core Location will cache data. The first reading it provides to your app is likely to be an old reading, which might or might not be accurate, depending on whether the phone has moved. Make sure to check the timestamp of any location and see if it's from before your app started.
  • I don't know what you mean by "power save" mode, but if you're thinking of when the screen is locked/off, that does not stop Core Location from running if your app is still running. On the contrary it's easy to run down your phone's battery much more quickly than you'd expect if you lock the phone while an app that uses Core Location is running, because the phone will continue to update the app as new location data is available. You could avoid this in your application by listening for UIApplicationWillResignActiveNotification to detect the screen locking, and UIApplicationDidBecomeActiveNotification to detect unlock.
  • Higher precision results will take more time to acquire, because the longer you wait, the better the results, up to a limit. If you decide you need to be within N meters, consider how long the user might have to stand there waiting for the phone to home in on its location.

Whether 20 meters is accurate enough is something only you can answer, based on how you expect your application to be used. Test the app and see if it works the way you want it to work.

Tom Harrington
[quote]•I don't know what you mean by "power save" mode, but if you're thinking of when the screen is locked/off, that does not stop Core Location from running if your app is still running.[/quote]I'm not sure if this is true. I get a fix (17m HDOP) - use lock button - wait 30 seconds - and after turning on (unlocking) again it takes some time to get a fix again - the first I get is a "bad" (about 1000 meters) fix.It looks as if locking results in "power safe mode" for location (it no longer uses GPS I would say)
ManniAT
When I wrote this answer, iPhone OS 3.0 was not even in public beta yet, so it may be less accurate now than it was at the time. The general techniques still apply but details of behavior when the screen is locked appear to have changed.
Tom Harrington
+14  A: 

Tom had a great answer (I wanted to note especially the usual return of the first value might be an older cached location) but I had a few more things to add:

  • You can tell the location manager to stop and start again if you want to force it to issue you at least one more location update.
  • If you were not aware, there are convenience methods in CLLocation to give you the distance between two locations.
  • As the docs note, you should implement locationManager:didFailWithError: even though you do not have to (if only to stop the location manager updates for a time).
  • Test thoroughly scenarios where the user disallows location updates for your application!
  • Very, very infrequently you may get updates out of order (i.e. you get a more accurate location followed by a slightly less accurate one dated earlier)
  • The simulator will give you a location update, but will always report your location as Apple HQ.
Kendall Helmstetter Gelner
Thanks much Kendall. I wish I could check your answer as well!
Keith Fitzgerald
Voting for this answer cos it actually gives really helpful tips about the usage.
Jann
A: 

Hi... I must be doing something wrong. When my app is running, and iPhone not locked I get regular updates (and NS log messages) from the location manager, but when I push the lock button, the NSLog events from my app stop, until I wake my phone again. Thoughts?

-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { if (startingPoint == nil) self.startingPoint = newLocation;

userLocation.latitude = newLocation.coordinate.latitude;
userLocation.longitude = newLocation.coordinate.longitude;

NSLog(@"Update from LM: Latitude = %f",newLocation.coordinate.latitude);
NSLog(@"                Longitude = %f",newLocation.coordinate.longitude);

}

mark
A: 

For normal situations, the didUpdateToLocation does not work any more when the lock/sleep button is pushed, and your app cannot get further coordinates during the locked period.

However, some apps CAN track during the locked period, and they will show the correct route when you unlocked and see the Mapview. Obviously there are ways to get the coordinates during the locked period.

That is what I am looking for... as well ...

Who has hints and further info, please post. Thanks.

lionfly
You should ask this as a separate question.
Dave DeLong
Thanks Dave, I will start a fresh one. But this is also an answer to the wrong comment of "when the screen is locked/off, that does not stop Core Location from running if your app is still running."
lionfly