ios - 如何使用 startMonitoringSignificantLocationChanges 检测位置变化

标签 ios cllocationmanager

根据 apple 文档,我使用 post iOS4 方法 startMonitoringSignificantLocationChanges 方法:

For applications that do not need a regular stream of location events, consider using the startMonitoringSignificantLocationChanges method to start the delivery of events instead. This method is more appropriate for the majority of applications that just need an initial user location fix and need updates only when the user moves a significant distance. This interface delivers new events only when it detects changes to the device’s associated cell towers, resulting in less frequent updates and significantly lower power usage.

所以这个接口(interface)只有在检测到位置发生变化时才传递新的事件,到底用什么方法可以检测到位置发生了明显的变化,到目前为止,我是这样的:

if ([CLLocationManager significantLocationChangeMonitoringAvailable]) {

        [locationManager startMonitoringSignificantLocationChanges];

    }

我应该使用什么显式方法来显式检测到位置已发生重大变化。谢谢。

最佳答案

我是这样做的:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


// Override point for customizatio-n after application launch.
id locationValue = [launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey];
if (locationValue)
{
    // create a new manager and start checking for sig changes
    [self log:@"didFinishLaunchingWithOptions location key"];
    m_locManager = [[CLLocationManager alloc] init];
    [self log:@"didFinishLaunchingWithOptions created manager"];
    m_locManager.delegate = self;
    [self log:@"didFinishLaunchingWithOptions set delegate"];
    [m_locManager startMonitoringSignificantLocationChanges];
    [self log:@"didFinishLaunchingWithOptions monitoring sig changes"];
    return YES;
}

[self log:@"didFinishLaunchingWithOptions"];    
return YES;
}

 - (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation

关于ios - 如何使用 startMonitoringSignificantLocationChanges 检测位置变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13341483/

相关文章:

android - React-Native:FlatList 中的反向 zIndex

javascript - 在 iOS 中播放 flv 视频

ios - 如果后台应用程序无法自动启动,Cardcase 如何在位置发生变化时启动?

ios - Swift iOS,CLLocationManager didUpdateLocations 记录未访问位置

ios - XCode Generic Archive 而不是 iOS app Archive

ios - 使用未声明的类型 'KIFTestActor'

ios - 为什么在 UISearchBar 上打字时 UISearchController 消失了?

swift2 - Swift 中 startMonitoringForRegion 之后的 RequestStateForRegion

ios - 通过 CLLocationManager 或 GoogleMap-IOS 跟踪用户行进的距离

ios - didUpdateToLocation 从未调用过