核心位置区域监控

jod*_*odm 6 iphone objective-c cllocationmanager cllocation ios4

有谁知道使用这个的任何知识:

- (void) startMonitoringForRegion:(CLRegion *)region desiredAccuracy:(CLLocationAccuracy)accuracy

我正在尝试将它实现到我的项目中,但是:

- (void) locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region

永远不会被称为?

有没有人有任何示例代码或知道为什么会发生这种情况?

我的代码如下.我在自己的LocationManager类中创建了一个这样的方法:

 - (void) locationManagerStartMonitoringRegion:(CLRegion *)region withAccuracy:(CLLocationAccuracy)accuracy {
    NSLog(@"Start Monitoring");
    [locationManager startMonitoringForRegion:region desiredAccuracy:accuracy];
    NSLog(@"Monitored Regions: %i", [[locationManager monitoredRegions] count]);
}
Run Code Online (Sandbox Code Playgroud)

然后我这样称呼它:

CLLocationCoordinate2D coordinates = CLLocationCoordinate2DMake(51.116261, -0.853758);     
CLRegion *grRegion = [[CLRegion alloc] initCircularRegionWithCenter:coordinates radius:150 identifier:[NSString stringWithFormat:@"grRegion%i", value]];

[locationManager locationManagerStartMonitoringRegion:grRegion withAccuracy:kCLLocationAccuracyBest];
Run Code Online (Sandbox Code Playgroud)

我得到NSLog的:

2011-01-30 19:52:26.409 TestingLocation [10858:307]开始监控

2011-01-30 19:52:27.103 TestingLocation [10858:307]受监控区域:

但是从来没有得到过NSLog:

 - (void) locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region     {
    NSLog(@"Entered Region");
}
Run Code Online (Sandbox Code Playgroud)

要么

 - (void) locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error {
    NSLog(@"monitoringDidFailForRegion: %@",error);
}
Run Code Online (Sandbox Code Playgroud)

谢谢

Noa*_*oon 5

您需要为区域监控工作移动相当长的路要走.它目前的粒度似乎是基于它何时从一个蜂窝塔传递到另一个蜂窝塔 - 在我的测试中,我不得不移动一英里或更长时间来注册我已经确定离开了我设置的一个小区域.