I'm having the following problem in my iPhone app:
I enable the location manager on a regular basis and I do wait for multiple location updates. When receiving a new location, I check the timestamp property of the new location to know whether it's an old location or not:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
numberOfUpdatesInInterval++;
NSLog(@"%d;%f;%f;%.0f;%@;%@;%@",
numberOfUpdatesInInterval,
newLocation.coordinate.latitude,
newLocation.coordinate.longitude,
newLocation.horizontalAccuracy,
newLocation.timestamp,
[self getCurrentDateAsString],
newLocation);
}
The problem I'm having now is that I receive new locations where the timestamp is new but the coordinates are still old locations I received earlier. I tested this when I was driving my car at 120km/h receiving the same coordinates multiple times but with different timestamps. I'm having the same problem in iOS 4 & 5.
How is this possible? Or how can I deal with this problem?
There are a few ways an iPhone gets its location.
The fastest location lookup is cell signal location. As long as you had data recently most of the local towers will be cached. Cell tower accuracy can range from 500m to 1500m or more.
The second fastest, provided you have data connectivity or have been in the area recently is wifi lookup. This will provide a very accurate location. The caveat is that you have to be around wifi and have a good data signal.
The slowest is GPS. The GPS in the iPhone is aGPS. It uses data from cell tower locations to get a better fix on your position. If the phone does not have a data connection and is not near wifi this can take between 2 and 4 minutes to get a fix. With cell tower information it can take 30 seconds.
From the apple docs:
When requesting high-accuracy location data, the initial event delivered by the location service may not have the accuracy you requested. The location service delivers the initial event as quickly as possible. It then continues to determine the location with the accuracy you requested and delivers additional events, as necessary, when that data is available.
In the car it will be less likely that you are near wifi locations and may have to wait longer for GPS lock on. If the locationManager believes you to still be in range of the previous location this may cause an old co-ordinate with a different time stamp.
Check the horizontalAccuracy of the data as well as the timestamp to determine if the location is as accurate as you requested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With