【发布时间】:2011-01-30 20:11:03
【问题描述】:
有谁知道使用这个的知识:
- (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);
}
谢谢
【问题讨论】:
-
你能发布你正在使用的代码吗?没有上下文就很难提供帮助。
-
代码现在添加到上面的原始帖子中。
-
您是否将 LocationManager 类设置为 CLLocationManager 的委托?
-
@jodm 仍然面临这个问题。你有没有解决这个问题。你能触发 didEnterRegion。请提供一个工作示例
标签: iphone objective-c ios4 cllocationmanager cllocation