核心位置区域监控 [英] Core Location region monitoring

查看:118
本文介绍了核心位置区域监控的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道使用它的任何知识:



- (void)startMonitoringForRegion:(CLRegion *)region desiredAccuracy:(CLLocationAccuracy)准确度



我正在尝试将其实施到我的项目中但是:



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



永远不会被调用?



有没有人有任何示例代码或知道为什么会这样?



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

   - (void)locationManagerStartMonitoringRegion:(CLRegion *)region withAccuracy :( CLLocationAccuracy)准确度{
NSLog(@开始监控);
[locationManager startMonitoringForRegion:region desiredAccuracy:accuracy];
NSLog(@监控区域:%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 TestingLocation [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 );
}

谢谢

解决方案

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

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

解决方案

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.

这篇关于核心位置区域监控的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆