如何从模拟器中的核心位置获得所需的准确度?

时间:2010-01-05 11:32:03

标签: objective-c iphone-sdk-3.0 core-location

我想在模拟器中检查所需的准确度,但我从来没有在didupdatetolocation方法中得到它。我知道在模拟器委托方法只被调用一次。有人知道如何在模拟器中获得所需的准确性。这是我的代码获取期望的准确性。

// Delegate method from the CLLocationManagerDelegate protocol.
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
    if (locationAge > 5.0)
    {
        self.DeviceOldLocation=newLocation;
        return;
    }
    LatitudeData = [[[[NSString alloc]  initWithFormat:@"%f",newLocation.coordinate.latitude] retain]autorelease];
    LongitudeData =[[[[NSString alloc] initWithFormat:@"%f",newLocation.coordinate.longitude] retain]autorelease];

    if (newLocation.horizontalAccuracy < 0)
        return;

    if (bestEffortAtLocation == nil || bestEffortAtLocation.horizontalAccuracy < newLocation.horizontalAccuracy)
    {
        // store the location as the "best effort"
        self.bestEffortAtLocation = newLocation;
        [self insertNewLocationInDataBase];
        if (newLocation.horizontalAccuracy <= Accuracy)
        {
            self.VeryAccuratelocation=newLocation;
            BestLocationAcquired=YES;
            [self insertNewLocationInDataBase];
            [self stopUpdatingLocation];                
            UIAlertView *BestLocation=[[UIAlertView alloc] initWithTitle:@"Best Location" message:@"best location found" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
            [BestLocation show];
            [BestLocation release];
        }
    }
}

1 个答案:

答案 0 :(得分:3)

在模拟器上,位置管理器始终以相同的精度返回相同的位置。因此,您应该在定位模拟器时调整精度阈值,或者只是在真实设备上测试位置服务。

#if TARGET_IPHONE_SIMULATOR
   double Accuracy = 100;
#else
  double Accuracy = 5;
#endif