我想检查模拟器中所需的准确性,但我从未在 didupdatetolocation 方法中得到它。我知道在模拟器中委托(delegate)方法仅被调用一次。是否有人知道如何在模拟器中获得所需的准确性。这是我要获取的代码所需的准确度。
// 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];
}
}
}
最佳答案
在模拟器上,位置管理器始终以相同的精度返回相同的位置。因此,您应该在定位模拟器时调整准确度阈值,或者仅在真实设备上测试位置服务。
#if TARGET_IPHONE_SIMULATOR
double Accuracy = 100;
#else
double Accuracy = 5;
#endif
关于objective-c - 如何从模拟器中的核心位置获得所需的精度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2005698/