I'm trying to get the actual position on the iPhone Simulator. But I always get the cached result. My question is related to this and this question. I'm using code from the LocateMe example:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
if (locationAge > 5.0) return;
if (newLocation.horizontalAccuracy < 0) return;
if (bestEffortAtLocation == nil || bestEffortAtLocation.horizontalAccuracy > newLocation.horizontalAccuracy) {
self.bestEffortAtLocation = newLocation;
if (newLocation.horizontalAccuracy <= locationManager.desiredAccuracy) {
[locationManager stopUpdatingLocation];
locationManager.delegate = nil;
latitude = newLocation.coordinate.latitude;
longitude = newLocation.coordinate.longitude;
}
}
}
But this doesn't seem to work right:
if (locationAge > 5.0) return;
If the GPS coordinates are older than 5 seconds the method will return. But in my case (iPhone Simulator) the method is only called once. So exiting the method isn't a good idea here. If I extract the location at the beginning of the method I get cached results. In the code example above I never get a coordinate.
What am I missing?
Edit 1:
Everything works fine on iPod touch.
Edit 2:
How can I force the locationManager to update its location? distanceFilter
is set to kCLDistanceFilterNone
, but it doesn't detect that the position changed a few kilometers.
How do I know the location data is ready? E.g. the location updates are coming every 10 seconds, do I have to introduce a pause? Because my application is immediately taking the existing value and is not waiting if the locationmanager is ready.
Edit 3:
After about a minute I get
Error: The operation couldn’t be completed. (kCLErrorDomain error 0.)
I have enabled wifi and the iPod touch and the MacBook Pro is in the same SSID. What am I doing wrong?
Edit 4:
Seems to be a problem with Xcode 3.2.4 and iOS 4.1. See also here. I'm not alone: CLLocationManager on iPhone Simulator fails with kCLErrorDomain Code=0 (Many more results on Google)
Edit 5:
In iOS 4 Apple uses its own database for geolocations. But I don't understand why there is a difference between iPod and MBP.
Edit 6:
Localization also doesn't work on iPad. Has anyone come up with a solution?