5

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?

wjans
  • 10,009
  • 5
  • 32
  • 43

2 Answers2

1

There are a few ways an iPhone gets its location.

  • cell signal
  • wifi access points
  • GPS satellites

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.

jackslash
  • 8,550
  • 45
  • 56
  • I even get this problem with a very good horizontal accuracy (i.e. 47.42m). The only problem is that the location is old but the timestamp has changed. I do understand that it gets cached, but then I would expect the timestamp to be the timestamp from when the location got captured earlier and not an updated (more recent) one. That way I cannot identify whether I haven't moved or received a older cached location. – wjans Jan 10 '12 at 20:02
  • If horizontal accuracy is valid and small and the timestamp is new it sounds like it might be a bug. If you have a Tech Support Incident left with your program you could raise one. – jackslash Jan 11 '12 at 21:47
0

Cllocation manager by default updates location as

locationManager.distanceFilter = kCLDistanceFilterNone;

which is why your are getting duplicate coordinates. actually it's updating the details very often even when there is change in ALTITUDE.

So best is you shall set

locationManager.distanceFilter = 4.0f; 

// this will send new location update details only when u move every 4 meters from your current location.

Manoj
  • 1,482
  • 2
  • 20
  • 53
  • I also got it fixed with the combination use of timestamp, horizontal frequency and distance filter.....Cheers :) – Harish Pathak Jul 07 '17 at 10:05
  • I stopped working on this project since April 2014. It's been 3 yrs now. So I don't know whats the case now. Good that you've located the solution. – Manoj Jul 07 '17 at 10:08