cllocationmanager - cllocation response object timestamp always less than one second old, why?
using the core location iphone api to get some locations.
It works fine, but one thing puzzles me. The ones i get back, i calculate their 'age' using the following code:
NSDate *eventDate = newLocation.timestamp;
NSTimeInterval locationAge = -[eventDate timeIntervalSinceNow];
i then print the age using:
NSLog(@"didupdateToLocation! lat: %f, lon: %f, accuracy: %f, age: %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude, newLocation.horizontalAccuracy, locationAge);
In my output, the age is ALWAYS less than one second. log examples:
2011-09-15 14:31:40.417 Nuba[1393:707] didupdateToLocation! lat: 59.340484, lon: 18.052089, accuracy: 816.373281, age: 0.055586
2011-09-15 14:31:40.495 Nuba[1393:707] didupdateToLocation! lat: 59.340484, lon: 18.052089, accuracy: 816.373281, age: 0.125578
2011-09-15 14:31:40.565 Nuba[1393:707] didupdateToLocation! lat: 59.340477, lon: 18.051996, accuracy: 999.848989, age: 0.019127
Why is this? Surely the first time, the phone didn't just "happen" to have a less than one second old location cached, every time?
Am i doing something wrong w开发者_JS百科hen i'm calculating the age?
It looks like you're calculating correctly. If location services are already in use by a background app or if you have cellular service then you could easily have a location already when you're app starts.
You don't display the accuracy so it's possible (likely) that your first location is low accuracy (ie: > 1000m horizontal error) location calculated from cell tower triangulation which is always available when the phone is on the cellular network.
精彩评论