views:

569

answers:

3

I'm writing a location based application, and I currently have an iPhone first gen, but I'm wondering how long it takes for an iPhone 3G or 3Gs to determine its location using the GPS chip ?

As far as I understand it, locationManager:didUpdateToLocation:fromLocation: may keep getting called with more and more accurate location information (there are no guarantees). So I would like to create a timer that if the user's location isn't determine by say time x then we simply stop trying to determine it and go with what we have.

Also, is there a way I can find out whether the device has a gps chip or not ? I know I can simply look at the device type in UIDevice and distingusih between touch and iphone, but how about iPhone without GPS and with GPS ?

Thanks!

+1  A: 

For your last answer I'd point you to this SO question. Based on whether its iPhone1,1 or iPhone1,2 you can tell whether or not it has a GPS chip.

For the first part of your question, I can tell you how I did it in my application. I start two timers, say a shortTimer and a longTimer, which both call the same callback method. The callback method waits until both timers have fired, and only after that continues to do some other work. Right after I start the timers, I start listening for location updates. If a location received in the locationManager:didUpdateToLocation:fromLocation method is recent and accurate enough, I fire the long timer prematurely (i.e. before it would fire itself).

This way, I wait at least shortTimer's timeout for a recent and accurate location, and at most longTimer's timeout. Reasonable values for those? Experiment a little I'd say. Because I have a splash screen with the company's logo before continuing, my shortTimer is rather long (i.e. 4 seconds). My longTimer is set at 20 seconds. This seems to be working for me.

HTH

drvdijk
A: 

I'd say let it try for a minute to determine your location. In my experience of triangulating my location on Google Maps in the iphone, it generally gives me an answer by that time. Of course, it depends on your granularity - if you request a kilometer accuracy you may get an answer faster than if you define best.

As for whether the device is an iPhone with GPS or not - the CoreLocation is designed to give you that answer without knowing/caring. Would you want to get the best available location if GPS is installed? If so, go with kCLLocationAccuracyBest and you'll get the most accurate updates that the device will support.

If you get a GPS lock, your accuracy (as measured by horizontalAccuracy) will be less than 10m. Anything bigger and you haven't got a GPS lock, or at least, not a good one.

You'll also find that the vertical accuracy will be present on a GPS enabled device and not enabled on a non-GPS device.

AlBlue
+1  A: 

I am not an expert on the GPS implementation in the iPhone but I can comment on the length of time that a GPS unit takes to find its location.

The time taken for the GPS to acquire the satellites and obtain a fix depends upon two things - the quality of the sky view and the amount that the GPS knows about the satellite constellation.

The first is important because the GPS has to be able to see the satellites to receive the signal. Here in the UK, if you are standing by a north facing wall then you will have a very poor view of the satellites as none of the orbits come more than about 50-55 degrees north so you will be limited to satellites that are low in the sky and at the northern extremes of their orbits.

The second factor is dependant upon how long it is since the GPS last saw the satellites and downloaded the orbital information (almanac and ephemeris). If the GPS has up to date satellite data and a good view then it can often find a new fix within a couple of seconds. If the GPS has lost power or the data is obsolete then it takes 32 seconds plus the satellite search time to load the new data. Time to first fix is usually around 45 - 50 seconds for most GPS engines that I have used.

Ian