6

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

- (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]);
}

然后我这样称呼它:

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];

我得到 NSLog 的:

2011-01-30 19:52:26.409 测试位置[10858:307] 开始监控

2011-01-30 19:52:27.103 测试位置[10858:307] 监控区域:

但永远不要从以下位置获取 NSLog:

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

或者

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

谢谢

4

5 回答 5

5

您需要走很长的路才能使区域监控的东西起作用。它当前的粒度似乎是基于它何时从一个蜂窝塔转移到另一个——在我的测试中,我必须移动一英里或更远才能让它记录我已经明确地离开了我设置的一个小区域。

于 2011-01-31T01:30:55.133 回答
1

在 ios 5 中提高了准确性。

于 2011-09-13T06:23:44.317 回答
1

答案是 :

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

在 ios 6.o 中已弃用。而是使用 `- (void) startMonitoringForRegion:(CLRegion *)region。

谢谢,阿卜杜勒`

于 2013-07-15T05:49:46.983 回答
1

好吧,您可以监视多个区域并在 Xcode 中模拟位置(从调试器上方的面板)以检查它是否正常工作。我已经测试过,它工作得非常顺利。

于 2015-03-11T07:12:20.973 回答
0

我必须看看你在哪里设置你的locationManager实例。但是正如@Mark Adams 试图逃避的那样,您需要将当前类设置为委托,locationManager以便它知道将消息发送回哪个类。它很简单:

locationManager.delegate = self;

于 2011-01-31T01:36:28.553 回答