views:

138

answers:

0

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 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 doesn't seem to work right:

if (locationAge > 5.0) return;

If the GPS coordinates are older than 5 seconds the method will be exited. But in my case (iPhone Simulator) the function 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 I'm missing?

Edit 1:

Everything works fine on iPod Touch.

Edit 2:

How can I force the locationManager to update his location? distanceFilter is set to kCLDistanceFilterNone, but he doesn't realize 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.)

WTF? I have enabled WIFI and the iPod Touch and the MacBook Pro is in the same SSID. What I'm 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: http://stackoverflow.com/questions/3110708 (Many more results on Google)

Edit 5:

Since the new iOS4 Apple uses a own database for geo-locations. 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?