核心位置区域监控

发布于 2024-10-14 18:23:35 字数 1667 浏览 7 评论 0原文

有谁知道使用此的任何知识:

- (void) startMonitoringForRegion:(CLRegion *)regiondesiredAccuracy:(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.409TestingLocation[10858:307]开始监控

2011-01-30 19:52:27.103 TestingLocation[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);
}

谢谢

Does anyone know any knowledge of using this:

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

I am trying to implement it into my project but:

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

is never being called?

Does anyone have any example code or know why this is happening?

My code is as follows. I created a method like this in my own LocationManager class:

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

I then call it like this:

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

I get NSLog's of:

2011-01-30 19:52:26.409 TestingLocation[10858:307] Start Monitoring

2011-01-30 19:52:27.103 TestingLocation[10858:307] Monitored Regions:

But never get an NSLog from:

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

or

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

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

追星践月 2024-10-21 18:23:35

您需要移动相当长的距离才能使区域监控功能发挥作用。它当前的粒度似乎是基于它从一个蜂窝塔切换到另一个蜂窝塔的时间——在我的测试中,我必须移动一英里或更远,它才能记录我确实离开了我设置的一个小区域。

You'll need to move rather a long way for the region-monitoring stuff to work. Its current granularity seems to be based on when it gets handed off from one cell tower to another—in my testing, I had to move a mile or more for it to register that I had definitively left a small region I'd set.

原来分手还会想你 2024-10-21 18:23:35

iOS 5 中的准确性得到了提高。

The Accuracy is improved in ios 5.

明媚殇 2024-10-21 18:23:35

答案是:

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

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

谢谢,
阿卜杜勒`

The Answer is :

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

is deprecated in ios 6.o. Instead use `- (void) startMonitoringForRegion:(CLRegion *)region.

Thanks,
Abdul`

九命猫 2024-10-21 18:23:35

那么您可以监视多个区域并在 Xcode 中模拟位置(从调试器上方的面板)以检查它是否正常工作。我已经测试过了,运行起来非常流畅。

Well you can monitor multiple regions and simulate location in Xcode (from the panel above the debugger) to check whether it's working or not. I've tested and it works pretty smooth.

醉态萌生 2024-10-21 18:23:35

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

locationManager.delegate = self;

I'd have to see where you setup your locationManager instance. But as @Mark Adams is trying to elude to, you need to set your current class as the delegate for locationManager so it knows which class to send messages back to. It is as simple as:

locationManager.delegate = self;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文