【问题标题】:Geofencing Indicator vs. Location Services Indicator地理围栏指标与定位服务指标
【发布时间】:2012-07-14 08:14:07
【问题描述】:

我有一个应用程序,它显示用户位置的地图并跟踪用户,直到应用程序移到后台。此时,位置管理器被告知停止更新位置,而是监视一个区域(最后一个已知位置周围 100 米半径)。在 iOS 模拟器上,它按预期工作并显示地理围栏指示器(与常规位置服务指示器相同,但只有轮廓)。在 iPhone 上,它似乎按预期工作,但显示的是常规位置服务图标,而不是单独的轮廓。

是否有任何原因可能会发生这种情况,模拟器和手机之间的这种差异?我只是想确保手机真的只使用地理围栏而没有其他服务(即确保最小电池使用情况)。

附加信息:

我已将后台模式设置为接收位置更新 - 这是在特定情况下(当用户启用它时)而不是一直。但是,我已尝试禁用此功能,但问题仍然存在。

我用于后台应用的代码:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Only monitor significant changes – unless specified
    if(!self.viewController.userSpecifiedToUseLocationServices)
    {
        // Stop using full location services
        [self.viewController.locationManager stopUpdatingLocation];

        // Create a boundary -- a circle around the current location
        self.viewController.currentBoundary = [[CLRegion alloc] initCircularRegionWithCenter:self.viewController.locationManager.location.coordinate radius:kSignificantLocationChange identifier:@"Current Location Boundary"];

        // Monitor the boundary
        [self.viewController.locationManager startMonitoringForRegion:self.viewController.currentBoundary desiredAccuracy:kCLLocationAccuracyBest];
    }
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Stop monitoring the region
    if(self.viewController.currentBoundary != nil)
    {
        [self.viewController.locationManager stopMonitoringForRegion:self.viewController.currentBoundary];
        self.viewController.currentBoundary = nil;
    }

    // Start full location services again
    [self.viewController.locationManager startUpdatingLocation];
}

【问题讨论】:

    标签: iphone ios objective-c mapkit core-location


    【解决方案1】:

    首先,模拟器上的定位服务从来都不是真实设备的高保真表示。因此,我不一定认为您会在两个测试平台上看到相同的内容。

    其次,根据this answer on stack overflow 的说法,这听起来像是 iOS 5 上的正常行为(显示不同的指标)。

    我还要提醒您,地理围栏并不是一种神奇的技术。该设备仍然必须使用定位服务,这会耗尽电池电量。我当然会推荐使用 Apple 的 startMonitoringForRegion:startMonitoringForRegion:desiredAccuracy: 并利用它们的实现,而不是自己编写代码。但是,我也不希望电池消耗可以忽略不计。

    最后,您将精度指定为kCLLocationAccuracyBest,而不是使用startMonitoringForRegion:,或指定较低的精度要求。我看不出这会如何影响电池性能。更高的准确性意味着操作系统必须要么获得更高质量的修复,要么更定期地轮询,或两者兼而有之。

    可悲的是,没有免费的午餐:(

    【讨论】:

    • 太棒了!感谢您的链接。事实证明,我已经开始监控以前版本的应用程序中的重大位置变化,而且它根本就没有停止过。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多