I am trying to get a real position on the iPhone Simulator. But I always get cached result. My question is related to this and this question . I use the 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 does not seem to work correctly:
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 called only once. Therefore, exiting the method here is not a good idea. If I extract the location at the beginning of the method, I get cached results. In the above code example, I never get the coordinates.
What am I missing?
Change 1:
Everything works fine on iPod touch.
Edit 2:
How to get locationManager agent to update its location? distanceFilter set to kCLDistanceFilterNone but does not detect that the position has changed by several kilometers.
How do I know if location data is ready? For instance. location updates appear every 10 seconds, do i need to enter a pause? Since my application immediately accepts the existing value and does not wait for the location manager to be ready.
Edit 3:
In a minute I get
Error: The operation could not be completed. (error kCLErrorDomain 0.)
I turned on Wi-Fi and iPod touch, and the MacBook Pro in the same SSID. What am I doing wrong?
Change 4:
There 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)
Change 5:
In iOS 4, Apple uses its own geolocation database. But I donβt understand why there is a difference between iPod and MBP.
Change 6:
Localization also does not work on the iPad. Has anyone come up with a solution?