objective-c - 如何从模拟器中的核心位置获得所需的精度?

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

我想检查模拟器中所需的准确性,但我从未在 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/

相关文章:

ios - iOS 8 中的 didEnterRegion - 区域监控

ios - 再次调出 "App Would Like to Use Your Current Location"对话

objective-c - 如何在 OpenGL 中正确正交渲染纹理?

iphone - 检查缩放级别是否改变

ios - 密码保护 iPhone 应用程序

iphone - 如何在 uiimagepickercontroller 中写入/获取图像的纬度经度?

ios 谷歌地图的准确性

ios - Tinder 个人资料动画

objective-c - xcode 8 自动缩进@property

iphone - UITableView 中的点击事件